WooCommerce B2B Sales Agents
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
if (function_exists("adp_functions")) { add_filter( 'woocommerce_stock_amount_cart_item', function ( $qty, $cart_item_key ) { return floatval( $qty ); }, 10, 2 ); add_filter( 'woocommerce_cart_item_price', 'b2b_wdp_cmp_edit_price', 15, 3 ); } function b2b_wdp_cmp_edit_price($price, $cart_item, $cart_item_key){ if ( is_user_logged_in() ) { $switchto_id = get_transient( 'wcb2bsa_switched_' . get_current_user_id() ); if ( $switchto_id && isset( $_COOKIE['wcb2bsa_switched'] ) ) { $attributes = apply_filters( 'wcb2bsa_cart_input', array( 'class' => 'input-text text', 'min' => '0', 'step' => '0.01' ) ); $field = sprintf( '<input type="number" name="cart[%s][wcb2bsa_custom_price]" value="%s" %s>', $cart_item_key, $cart_item['data']->get_price(), implode( '', array_map( function( $key, $value ) { return sprintf( ' %s="%s"', $key, $value ); }, array_keys( $attributes ), $attributes ) ) ); return $field; } } return $price; } |
Also, the option “Apply discount on “Onsale” products” (Pricing rules > Settings > Calculation) has to be set to “Discount sale price”.