0

I'm editing my content-product.php file in my child theme, because i want to create custom woocommerce loops.

For now, i've put everything in a big if ( is_woocommerce() );. With an else with my own code inside.

The problem is that now, if i use the shortcode [product] and [best_selling], or every other woocommerce shortcode in a page, i get the same (wrong) layout.

So i just need to check which shortcode is calling my template.

Example: As i said, i have a if ( is_woocommerce() ); condition.

If the page is woocommerce, it will show the default template.

Then there is an else, so every other page loads the 2nd template.

I want to check which shortcode is beign used to load that template, so i can do something like:

switch (shortcode_used)

case 'single_product':
    code

case 'best_selling'
    code

etc.

Thank you in advance. -Kryuko

  • 2
    i don't understand what you mean by "wrong layout". edit your question to add more details and examples. – mmm Mar 29 '18 at 16:47
  • 3
    If you're trying to figure out if the shortcode is loading your template so you can make it do something different, that seems like a suboptimal approach. content-product.php is used by WooCommerce, it wouldn't surprise me if any shortcode that displays a product uses that template. So some clarification is needed in your question. What makes it the right or wrong layout? – Tom J Nowell Mar 29 '18 at 16:58
  • As i said, i have a if ( is_woocommerce() ); condition. If the page is woocommerce, it will show the default template. Then there is an else, so every other page loads the 2nd template. I want to check which shortcode is beign used to load that template, so i can do something like: switch (shortcode_used) case 'single_product': code case 'best_selling' code etc. – Kryuko Mar 30 '18 at 10:27
  • I've looked at the woocommerce shortcode php file, but i didn't understood how check which shortcode is used. – Kryuko Mar 30 '18 at 10:52
  • I've found the shortcode_atts function, but i didn't understood if i can use it for what i need. – Kryuko Apr 4 '18 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.