Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Product price

  • Hi,
    I have a catalogue in which all products are discounted.
    For Black Friday, an additional discount will be applied to the entire catalogue, applied to the discounted price.
    I need the 3 prices to appear in the loop and on the product page: | original price | discounted price | discounted price – discount on the whole catalogue.
    Woocommerce only shows the discounted price and (discounted price – discount on the whole catalogue).

    With this function I recover the original price, for simple or variable products:

    function show_origianl_price() {
        global $product;
        if ( $product->is_type( 'simple' ) ) {
            $price = $product->get_regular_price();
        } elseif ( $product->is_type( 'variable' ) ) {
            $max_percentage = 0;
            foreach ( $product->get_children() as $child_id ) {
                $variation = wc_get_product( $child_id );
                $price = $variation->get_regular_price();
            }
        }
    }

    How do I insert $price in the product price block?

    Thank you!

    ps: sorry for my English 🙂

  • Hi there,

    you would need to ask Woocommerce Support , as i do not know if that is possible to add that to the Price Block.

  • Hi David,

    and I can put it in a customised block that I can then put wherever I want?

  • But its not just a case of displaying a price. You would need to add the function that adjusts the price of the produce, so when the customer adds it to the cart it will have the right price

  • I did this and it works.
    The currency changes based on the shipping country and I manage it with JS.

    add_action( 'woocommerce_single_product_summary', 'db_show_price', 5 );
    add_action('woocommerce_shop_loop_item_title','db_show_all_price');
      
    function db_show_price() {
        global $product;
        if ( $product->is_type( 'simple' ) ) {
            $price = $product->get_regular_price();
        } elseif ( $product->is_type( 'variable' ) ) {
            $max_percentage = 0;
            foreach ( $product->get_children() as $child_id ) {
                $variation = wc_get_product( $child_id );
                $price = $variation->get_regular_price();
            }
        }	
    	$price = number_format($price, 2, ',', ' ');
        echo "<p class=\"price\" style=\"margin-bottom: 0em;\"><span class=\"wcpbc-price\"><del><span class=\"woocommerce-Price-amount amount\"><bdi>" . $price . "&nbsp;<span class=\"woocommerce-Price-currencySymbol\"></span></bdi> </span></del></span></p>"; 
    }
    function db_show_all_price() {
        global $product;
        if ( $product->is_type( 'simple' ) ) {
            $price = $product->get_regular_price();
        } elseif ( $product->is_type( 'variable' ) ) {
            $max_percentage = 0;
            foreach ( $product->get_children() as $child_id ) {
                $variation = wc_get_product( $child_id );
                $price = $variation->get_regular_price();
            }
        }	
    	$price = number_format($price, 2, ',', ' ');
        echo "<span class=\"price\" style=\"margin-bottom: -10px;\"><span class=\"wcpbc-price\"><del><span class=\"woocommerce-Price-amount amount\"><bdi>" . $price . "&nbsp;<span class=\"woocommerce-Price-currencySymbol\"></span></bdi></span></del> </span></span>"; 
    }
    

    I post this, it might be useful to others.

  • Thats great – and thanks for sharing that!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.