H
H
hypero2018-08-19 14:43:08
WordPress
hypero, 2018-08-19 14:43:08

New information in Woocommerce product card?

Hello.
There is a page with Woocommerce products. How to add some new block in the product card and on the product page?
I know that this is done by hooks, for example through woocommerce_single_product_summary, but in this case, the information is added after the entire container. How to do to display the information valid after the price?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2018-08-19
@hypero

All Woocommerce templates are stored in the plugin folder in templates. All these templates are named so that you can guess what they are responsible for. You can override each of these templates in your theme and change as you like, as written in each file:

<?php
/**
 * The template for displaying product content in the single-product.php template
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/content-single-product.php.
 *

If you do not need to change the file much, you can limit yourself to hooks. Each file is well documented which hooks are called and with what priority. For example, a file /templates/content-single-product.php
Here is a fragment where information about the product is displayed
<div class="summary entry-summary">
    <?php
      /**
       * Hook: woocommerce_single_product_summary.
       *
       * @hooked woocommerce_template_single_title - 5
       * @hooked woocommerce_template_single_rating - 10
       * @hooked woocommerce_template_single_price - 10
       * @hooked woocommerce_template_single_excerpt - 20
       * @hooked woocommerce_template_single_add_to_cart - 30
       * @hooked woocommerce_template_single_meta - 40
       * @hooked woocommerce_template_single_sharing - 50
       * @hooked WC_Structured_Data::generate_product_data() - 60
       */
      do_action( 'woocommerce_single_product_summary' );
    ?>
  </div>

all hooks in the woocommerce_single_product_summary action and their priorities are written in the comment. If you need to display something between price (10) and quote (20) - you need to create a hook with a priority between 10 and 20. If you need to remove something, just write remove_action, if you swap, then delete the hooks and register them yourself, but with different priorities.
For example:
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
 
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 10);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 20);

Swaps the price and quote.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question