add image beside woocommerce product description in tab - php

I am trying to place an image next to the product description in the tabs of woocommerce. The code I am trying to use is this:
add_action('woocommerce_template_product_description', 'badge', 25);
function badge() {
echo '<div class="badge"><img src="URL" style="width:175px;height:175px;"></div>';
}
I have not had any luck in getting it to display, and am thinking that the 'woocommerce_template_product_description' maybe the problem - I'm sure if I am targeting the product description correctly. I think tabs are increasing the complexity of the solution.
Using the code below the image displays next to the product summary.
add_action('woocommerce_single_product_summary', 'badge', 25);
function badge() {
echo '<div class="badge"><img src="URL" style="width:175px;height:175px;"></div>';
}
I would appreciate some help is solving this problem.

After much head scratching I think I might have figured it out. This code seems to work:
add_filter( 'woocommerce_product_tabs', 'magva_badge', 98 );
function magva_badge( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
return $tabs;
}
function woo_custom_description_tab_content() {
woocommerce_product_description_tab(); echo '<div class="magva_badge"><img src="https://www.magva.com/wp-content/uploads/2015/10/made_in_ireland.png" style="width:175px;height:175px;"></div>';
}

Related

Add shortcode to WooCommerce product description

I am trying to auto-add some shortcode at the end of every woo product description. (not after short description). The code with which I am trying is:
add_filter('product_descr','ce_add_text_short_descr');
function ce_add_text_short_descr($description){
$text="[my-shortcode-goes-here]";
return $description.$text;
}
That one is not working for me. can someone help me?
add_filter('the_content', 'mujuonly_alter_product_description');
function mujuonly_alter_product_description($description) {
if (is_product()) {
$text = do_shortcode('[products limit="4" columns="4" orderby="popularity" class="quick-sale" on_sale="true" ]');
return $description . $text;
}
return $description;
}
This way using the hook the_content you can update the product description using the shortcode
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
$text = do_shortcode('[my-custom-text]');
return $description.$text;
}
You are making mistake with woocommerce hook and if we neeed to print a shortcode in a php file it works with do_shortcode(); Hope it will work on your side I have already tested it.
Don't forget to replace my-custom-text with your shortcode.

WooCommerce - Add content on the thank you page by the shipping method

I would like to place my own content (in my case a shortcode) on the thank you page at WooCommerce after completing the order, which depends on the shipping method.
So for example:
Shipping Method 1: Content 1
Shipping Method 2: Content 2
Shipping Method 3: No content
I have already found something for text here, but i dont get the shortcode inserted. Alternatively I have tested what works with the shortcode here, where the dependency on the shipping method is missing.
Maybe someone can help me to implement this.
Ideally the content should be above the table with the order information.
Thanks a lot!
May be the way you added the shortcode to the thank you text can be the issue.
See the following shortcode function called avengers which i created for demo.
function call_avangers( $atts ){
return "<p>Avengers . . . . Assemble !!!</p>";
}
add_shortcode( 'avengers', 'call_avangers' );
You can display this shortcode in thank you page using the below function
add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $text, $order ) {
if( $order->get_shipping_method() == 'your_shipping_method_here' ) {
$text .= do_shortcode('[avengers]');
}
return $text;
}
The basic thing is you have to call do_shortcode('your_shortcode_name')

How to hook an ACF field into the bottom of the "after_shop_loop" section of a Woocommerce category page after pagination

I found the correct hook of where I want the field to show which is below
add_action( 'woocommerce_after_shop_loop', 'after_shop_loop', 1 );
This code works exactly how'd I'd like mine to work but with an ACF text area field. Ideally, I'd like it to show under the pagination. This hook is currently showing above the pagination.
add_action( 'woocommerce_after_shop_loop', 'after_shop_loop', 1 );
function after_shop_loop() {
echo "<div class='best-seller'>
<h3>If you need help or have a question for Customer Service, please visit the <a href='#'>Help Section.</a></h3>
</div";
}
I'd like to create a function to bring in an ACF text area that I've added to the backend for all brands that are coming from WooCommerce taxonomy pages "Brand".
This is what I have so far with no luck. Is there something I'm doing wrong or something special you have to do to get ACF to show on Taxonomy pages? Any help is appreciated. Thanks in advance...
add_action( 'woocommerce_after_shop_loop', 'after_shop_loop', 1 );
function custom_after_shop_loop() {
$brand_content = get_field('brand_bottom');
if( !empty($brand_content) ) {
echo '<div class="brandbottom">' . $brand_content . '</div>';
}
}
Screenshots from my custom field.
Missing "custom_" in the name of your function and you have to get the current taxonomy term. Tested and works
add_action( 'woocommerce_after_shop_loop', 'custom_after_shop_loop', 1 );
function custom_after_shop_loop() {
$term = get_queried_object();
$brand_content = get_field('brand_bottom', $term);
if( !empty($brand_content) ) {
echo '<div class="brandbottom">' . $brand_content . '</div>';
}
}

WooCommerce "CONTACT" button when out of stock

Trying to achieve something that should be simple, but I've tried 3 approaches with multiple code variations and I just can't make it work. I'm trying to create a button that will appear in place of the "ADD TO CART" button on single product pages when the item is out of stock. Clicking the button will fire a popup contact form.
Is creating an add action in functions the right way to go, or should I replace the normal button with an if statement? I've tried both, so help with coding either would be greatly appreciated.
You can either hook into woocommerce_loop_add_to_cart_args using a filter in your functions.php or edit the template file directly by pulling it into your theme. Either way will require a bit of PHP.
If doing it in your functions.php, it would look something like this (untested but should send you down the right path):
<?php
add_filter( 'woocommerce_loop_add_to_cart_link', 'my_out_of_stock_button' );
function my_out_of_stock_button( $args ){
global $product;
if( $product && !$product->is_in_stock() ){
return 'Contact us';
}
return $args;
}
I don't know what your button code should actually look like or what other information you need to capture, but this is how you could override the "Add to Cart" button and replace it if out of stock.
UPDATE
LoicTheAztec brought up a great point - the filter provided only affects the button on the archive, category, tag overview pages - not the individual product pages. There are no hooks for the individual product page buttons BUT you can copy the templates to your theme and override them.
You'll want to look at the files in templates/single-product/add-to-cart. Use a similar if statement as above:
#simple.php
<?php if ( $product->is_in_stock() ) : ?>
// Standard WooCommerce code
<?php else: ?>
// Your button code
<?php endif; ?>
Just add below code in functions.php file of your enabled theme reference
add_action('woocommerce_after_shop_loop_item', 'themelocation_change_outofstock_to_contact_us', 1);
// for shop page
function themelocation_change_outofstock_to_contact_us() {
global $product;
if (!$product->is_in_stock()) {
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart');
//change the link to your contact us page
echo ' Contact Us ';
}
}
// for single page
add_filter('woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability($availability, $_product) {
// Change In Stock Text
if ($_product->is_in_stock()) {
$availability['availability'] = __('Available!', 'woocommerce');
}
// Change Out of Stock Text
if (!$_product->is_in_stock()) {
$availability['availability'] = __(' Contact Us ', 'woocommerce');
}
return $availability;
}
I was looking for a way to show a contact button on bespoke products and
#ahwychkchih solution works great. One issue I had though is that schema markup will show as out of stock for those products which is not the case for beskpoke products is just they can't be purchased straight away so I've added this to force in_stock markup for my products. I'm aware that this solution would affect all products so you can always add a product id filter if needed
// Force In Stock schema markup
function fix_my_product_offers_schema ($markup_offer, $product) {
if (!$product->is_in_stock()) {
$markup_offer['availability'] = 'https://schema.org/InStock';
}
return $markup_offer;
}
add_filter('woocommerce_structured_data_product_offer', 'fix_my_product_offers_schema', 1, 2);

How to remove Text area of comment in Wordpress?

Hellow there all I tried searching everywhere but I coudn't just find it - may be because its a wiered requirement all I want to do is remove my Comment Text area in wordpress comment - I sucessfully removed URL website and name in the comment field by using following code
<?php
function remove_comment_fields($fields) {
unset($fields['url']);
unset($fields['author']);
unset($fields['email']);
return $fields;
}
add_filter('comment_form_default_fields','remove_comment_fields');
?>
But not able to remove the Text area - Actually you all will thought what will I do removing all this I am using a plugin which allow you to post images in your comment and the only option I want to give to user is post images via comment. please guide me.
Two options, the comment_form_defaults filter:
add_filter( 'comment_form_defaults', 'so16856397_comment_form_defaults', 10, 1 );
function so16856397_comment_form_defaults( $defaults )
{
$defaults['comment_field'] = '';
return $defaults;
}
or the comment_form_field_comment filter:
add_filter( 'comment_form_field_comment', 'so16856397_comment_form_field_comment', 10, 1 );
function so16856397_comment_form_field_comment( $field )
{
return '';
}
Check the comment_form source code.
You can also hide the textarea comment box by taking its id set to display:none from CSS
Just simple, add this code in functions.php file
function disable_comments_everywhere( $open, $post_id ) {
return false;
}
add_filter( 'comments_open', 'disable_comments_everywhere', 10 , 2 );

Categories