Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
994 views
in Technique[技术] by (71.8m points)

wordpress - woocommerce, how can i add additional cost in cart product total price?

I want to add additional cost in the cart product total price, not in product price nor the whole cart total price. I am referring about the product total price.

Right now i have not not try and I don't have any code.

add_action( 'woocommerce_before_calculate_totals', 'function add_additional_price' );
function add_additional_price( $cart_object ) {
    $custom_price = 10; // This will be your custome price  
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can try this

// Change the line total price
add_filter( 'woocommerce_get_discounted_price', 'calculate_discounted_price', 10, 2 );
// Display the line total price
add_filter( 'woocommerce_cart_item_subtotal', 'display_discounted_price', 10, 2 );

function calculate_discounted_price( $price, $values ) {
    // You have all your data on $values;
    $price += 10;
    return $price;
}

// wc_price => format the price with your own currency
function display_discounted_price( $values, $item ) {
    return wc_price( $item[ 'line_total' ] );
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...