Sample Product, change location of Price | Wordpre

2019-08-09 04:38发布

问题:

I am trying to change the location of Price of all sample Products from the current location, which is below the title to just about "add to cart".
If i do it with CSS, that is affecting the responsiveness of the website.
i want to make this change on a PHP, so that it can impact all the SAMPLE products which i upload now on..
can i make any changes on the PHP so that the "SAMPLE Product" Price always shows up just above "add to cart" ?

at present:

what i need is:

the code in content-single-product.php

<div class="single clearfix  row-fluid">
        <div class="wrap span6 product-left">
            <?php
                /**
                 * woocommerce_show_product_images hook
                 *
                 * @hooked woocommerce_show_product_sale_flash - 10
                 * @hooked woocommerce_show_product_images - 20
                 */
                do_action( 'woocommerce_before_single_product_summary' );
            ?>
        </div>
        <div class="span6">
            <div class="product-detail">
                <?php
                    /**
                     * woocommerce_single_product_summary hook
                     *
                     * @hooked woocommerce_template_single_title - 5
                     * @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
                     */
                    do_action( 'woocommerce_single_product_summary' );
                    //echo  do_shortcode("[yith_wcwl_add_to_wishlist]");
                ?>
            </div>
        </div>
    </div>

回答1:

In the below code, you are overwriting the WooCommerce hook inclusion/priority order. So the price will be included after woocommerce_template_single_excerpt which has a priority value of 20

Include the following code in functions.php.

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );


回答2:

WooCommerce displays the price between the product title and product description on the single product page by default.

If you’d like to move the price after the content, you can do so easily by adding the following hook to your theme’s functions.php file:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );

By changing the number from 10 to 25, you move the price below the single excerpt (which has a priority of 20).

The WooCommerce templates/content-single-product.php file shows the hook priorities for the single product loop.

Here you can get WooCommerce Action and Filter Hook -https://docs.woothemes.com/wc-apidocs/hook-docs.html