• Resolved Mrskt

    (@mrskt00)


    Hi,

    Suppose This is my Shortcode: [mbv name=”product-info”]

    And i want to display this shortcode’s content before WooCommerce Tabs.
    Or after WooCommerce product gallery.

Viewing 15 replies - 1 through 15 (of 18 total)
  • Try:

    add_action( 'woocommerce_after_single_product_summary', 'my_content', 5 );
    function my_content() {
      print do_shortcode ( '[mbv name="product-info"]' );
    }

    Code goes in functions.php for your child theme or you can try a PHP snippets plugin.

    Be sure to use straight quotes for your shortcode parameter, not smart quotes.

    If it doesn’t work, state your theme.

    Thread Starter Mrskt

    (@mrskt00)

    Hi @lorro It’s working..

    I seened the the code there is only woocommerce_after_single_product_summary, Can you tell why you added “my-content” and “5” for?

    I am noob at PHP that’s why asking, Just for Knowledge.

    Have a look at the template for the product page:
    wp-content/plugins/woocommerce/templates/content-single-product.php

    ‘woocommerce_after_single_product_summary’ is a point in the template code where extra code can be inserted.

    The second parameter in the add_action() function is the name of the inserted new function containing the extra code.

    The third parameter in the add_action() function is the priority. The priority becomes important if there is more than one bit of extra code to go in. The lower the priority number, the sooner the extra code is run.

    The template shows us that the function ‘woocommerce_output_product_data_tabs’ is run at priority 10. You wanted your shortcode to run before that, so we use say a 5 which comes before the 10.

    Thread Starter Mrskt

    (@mrskt00)

    Hi @lorro I followed your trick And used

    add_action( 'woocommerce_template_loop_product_title', 'my_shcontent', 5 );
    function my_shcontent() {
      print do_shortcode ( '[rwmb_meta id="launched_on" ]' );
    }

    this code to show a custom field’s shortcode content after WooCommerce loop product title. If you don’t mind can you what is the right codes to do this?

    My Desired Shortcode are [rwmb_meta id=”launched_on”] and [rwmb_meta id=”product_type”]

    • This reply was modified 3 years, 6 months ago by Mrskt.

    The hooks you could use are listed here:
    https://woocommerce.github.io/code-reference/hooks/hooks.html
    I can’t see ‘woocommerce_template_loop_product_title’ there.

    Have a look at the template for the product page:
    wp-content/plugins/woocommerce/templates/content-single-product.php

    To go after the title, you would use:
    add_action( ‘woocommerce_single_product_summary’, ‘my_shcontent’, 8 )
    The title is at priority 5.

    Thread Starter Mrskt

    (@mrskt00)

    @lorro I think this one woocommerce_after_shop_loop_item_title is that title?

    Thread Starter Mrskt

    (@mrskt00)

    Hi @lorro I just tried now the below code and it worked:

    
    add_action( 'woocommerce_after_shop_loop_item_title', 'my_shcontent', 5 );
    function my_shcontent() {
      print do_shortcode ( '[rwmb_meta id="version" ]' );
    }

    But I want to use two shorcodes then what code i have to use.

    I’d not spotted that we’ve moved from the product page to the shop page. The shop page template is here:
    wp-content/plugins/woocommerce/templates/content-product.php

    The hook you are looking for is: ‘woocommerce_shop_loop_item_title’. The function woocommerce_template_loop_product_title() is at priority 10, so to go after the title, you would use:
    add_action( ‘woocommerce_shop_loop_item_title’, ‘my_shcontent’, 20 );

    Just use another print do_shortcode(); after the first one.

    Thread Starter Mrskt

    (@mrskt00)

    @lorro After doing this, Both goes too close how can i give white space between theme?

    You’ll need to use some custom css.

    For advice, please post the address of a relevant page.

    Thread Starter Mrskt

    (@mrskt00)

    @lorro Ok, Thank you so much… my biggest problem is solved now

    Plugin Support Stuart Duff – a11n

    (@stuartduff)

    Automattic Happiness Engineer

    Hey?@mrskt00,

    That’s great to hear @lorro helped you to get this resolved – if you have any further questions, you can reopen it again if you need be.

    Thread Starter Mrskt

    (@mrskt00)

    @stuartduff It’s completely solved now,But my current problem is posted here: https://www.ads-software.com/support/topic/how-to-enable-downloadable-options-by-default/

    If you can help then please try ??

    Thread Starter Mrskt

    (@mrskt00)

    @lorro Can you tell me How can i exclude in specific category’s products page.

    Thanks

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘How to Display Shortcode’s Content before tabs?’ is closed to new replies.