• Resolved jazzu

    (@jazzu)


    Hello!

    I’m looking for a free plugin or another solution to add a Price per Unit calculator to 5 of my products. I don’t want the official WooCommerce’s Measuring Price Calculator, because like I said, I only have 5 products (out of 550) where the customer picks the lenght of the product. I tried a few plugins already, but the issue is that I made custom Single Product Pages in Elementor.

    The price is currently shown with this code:

    function custom_price_shortcode_callback( $atts ) {
        $atts = shortcode_atts( array(
            'id' => null,
        ), $atts, 'product_price' );
        $html = '';
        if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){
            // Get an instance of the WC_Product object
            $product = wc_get_product( intval( $atts['id'] ) );
            // Get the product prices
            $price         = wc_get_price_to_display( $product, array( 'price' => $product->get_price() ) ); // Get the active price
            $regular_price = wc_get_price_to_display( $product, array( 'price' => $product->get_regular_price() ) ); // Get the regular price
            $sale_price    = wc_get_price_to_display( $product, array( 'price' => $product->get_sale_price() ) ); // Get the sale price
            // Your price CSS styles
            $style1 = 'style="font-size:25px;color:#FF0000;font-weight:bold;"';
            $style2 = 'style="font-size:17px;color:#5F5F5F"';
            // Formatting price settings (for the wc_price() function)
            $args = array(
                'ex_tax_label'       => false,
                'currency'           => 'EUR',
                'decimal_separator'  => ',',
                'thousand_separator' => '.',
                'decimals'           => 2,
                'price_format'       => '%2$s %1$s',
            );
            // Formatting html output
            if( ! empty( $sale_price ) && $sale_price != 0 && $sale_price < $regular_price )
                $html = "<del $style2>" . wc_price( $regular_price, $args ) . "</del> <ins $style1>" . wc_price( $sale_price, $args ) . "</ins>"; // Sale price is set
            else
                $html = "<ins $style1>" . wc_price( $price, $args ) . "</ins>"; // No sale price set
        }
        return $html;
     }

    What would be the best approach to this? Appreciate any help I’ll get with this.

    Kind regards

    • This topic was modified 2 years, 5 months ago by jazzu.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • @jazzu

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.
    
    I can also recommend <a href="https://developer.woocommerce.com/" rel="noopener" target="_blank">the WooCommerce Developer Resources Portal</a> for resources on developing for WooCommerce.
    
    You can also visit the <a href="https://www.facebook.com/groups/advanced.woocommerce/" rel="noopener" target="_blank">WooCommerce Facebook group</a> or the <code>#developers</code> channel of the <a href="https://woocommerce.com/community-slack/" rel="noopener" target="_blank">WooCommerce Community Slack</a>. We're lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.
Viewing 1 replies (of 1 total)
  • The topic ‘Need advice with Price per unit (plugins / functions code, etc) in some products’ is closed to new replies.