• Resolved daxtrader54

    (@daxtrader54)


    Here’s a tricky one for you.

    I am using PPOM PRO to have an additional length input for my variable products. And it’s great!

    I also use a custom snippet to calculate the weight of my items and the weight of my cart.

    This weight solution no longer works properly because my new PPOM PRO ‘measure input’ field for length is not connected to the calculation.

    So I need to modify my weight calculation to update the weights by multiplying the length variable from your plugin.

    Can you tell me how to get find the input data from the length variable please?

    Here is my current weight solution:

    
    // Snippet 1 - Total Cart Weight
    // START
    // This snippet displays the total cart weight at the top of the basket/cart page, with a message saying "your cart weight is: __ kg"
    
    add_action('woocommerce_before_checkout_form', 'bbloomer_print_cart_weight');
    add_action('woocommerce_before_cart', 'bbloomer_print_cart_weight');
    function bbloomer_print_cart_weight( $posted ) {
    	global $woocommerce;
    	$notice = 'Your cart weight is: ' . $woocommerce->cart->cart_contents_weight . get_option('woocommerce_weight_unit');
    	if( is_cart() ) {
    	   wc_print_notice( $notice, 'notice' );
    	} else {
    	   wc_add_notice( $notice, 'notice' );
    	}
    }
    // END 
    
    // Snippet 2 - Individual item weights
    // START
    // This snippet displays the individual weight for each item on the basket/cart page, with a message saying "Weight of item: __ kg"
    
    add_filter( 'woocommerce_get_item_data', 'displaying_cart_items_weight', 10, 2 );
    function displaying_cart_items_weight( $item_data, $cart_item ) {
        $item_weight = $cart_item['data']->get_weight() * $cart_item['quantity'];
        $item_data[] = array(
            'key'       => __('Weight of item', 'woocommerce'),
            'value'     => $item_weight,
            'display'   => $item_weight . ' ' . get_option('woocommerce_weight_unit')
        );
        return $item_data;
    }
    // END
    

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • N-Media

    (@nmedia)

    Hi,

    you can get PPOM fields from session using this snippet:

    $cart_item['ppom']['fields']

    $cart_item is variable under woocommerce_get_item_data hook.

    Thread Starter daxtrader54

    (@daxtrader54)

    Thank you

    For those having a similar issue, the solution for me was

    $cart_item['ppom']['fields']['YOUR CUSTOM FIELD ID HERE']

    I also had to add a conditional if statement, to weed out any products that did NOT use the additional field.

    N-Media

    (@nmedia)

    Thanks for update.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘PPOM PRO Weight calculation’ is closed to new replies.