简体   繁体   中英

How can I make the price of WooCommerce variations products go up when selecting the options?

I have a problem what happens is that I am trying to make the price of the variations of WooCommerce go up automatically when selecting the options and I succeeded.

But the problem is that when I create a product with a single price range, the code doesn't work for me since when selecting the options the PRICE DISAPPEARES . Could you help me solve it?

I will attach an image of how the price disappears when selecting the options instead of going up.

ERROR

Here I attach the link of the product with error: Link

Contrary to the previous example, I will put a screenshot of a product that works correctly and does go up in price. Apparently it works as there are variables with different prices as I have tried to do that and it works correctly.

It would just be to make it work as well when in the same price range.

FUNCTIONAL EXAMPLE

Here I will attach the link of the FUNCTIONAL product: Link

The code I'm testing is this but as I told you, being a variable product with a range of equal prices, it doesn't work to raise the price and instead the price DISAPPEARES.

`

add_action( 'wp_footer', 'dcms_add_script_footer' );

function dcms_add_script_footer() {
    if ( ! is_product() ) return;
    ?>
        <script>
        jQuery(function ($) {

            $('.variations_form').on('woocommerce_variation_has_changed', function () {
                const container_price_top = 'p.price';
                const container_price_bottom = '.woocommerce-variation-price';

                $(container_price_top).empty();

                setTimeout(function(){
                    if ( $(container_price_bottom).is(":visible") ){
                        const content = $(container_price_bottom).html();
                        $(container_price_top).html(content);
                        $(container_price_bottom).hide();
                    }
                }, 500);
            });

        });
        </script>
    <?php
}

`

Actually the link with url that you posted as functional preset it disappears too the price. Is there any chance to get the cached version of your site and not the current phase?

FYI I didn't see any functional product in this url with this way!

If I understand you want seperated price by variation?

ie iPhone 13 Pro Max 128GB has 1500 EUROS but when you have to select the variation with 256 GB you need to increase the price to 1800 EUROS. Is that correct? Cause this can simply solved by setting your variation price in variable product type.

Friendly, George

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM