价格应添加在购物车页面上,并应在Woo-commerce中以购物车总计进行计算

时间:2019-12-17 07:11:00

标签: php wordpress woocommerce

// Backend Variation - Add / Display Refundable Deposit Field
add_action( 'woocommerce_variation_options_pricing', 'add_variation_options_pricing_msrp', 10, 3 );
function add_variation_options_pricing_msrp( $loop, $variation_data, $variation ){

    woocommerce_wp_text_input( array(
        'id' => '_msrp_'.$loop,
        'wrapper_class' => 'form-row form-row-first',
        'class' => 'short wc_input_price',
        'label' => __( 'Refundable Deposit', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',
        'value' => wc_format_localized_price( get_post_meta( $variation->ID, '_msrp', true ) ),
        'data_type' => 'price',
    ) );
}

// Backend Variation - Save Refundable Deposit Field value
add_action( 'woocommerce_save_product_variation','save_variation_options_pricing_msrp',10 ,2 );
function save_variation_options_pricing_msrp( $variation_id, $loop ){
    if( isset($_POST['_msrp_'.$loop]) )
        update_post_meta( $variation_id, '_msrp', wc_clean( wp_unslash( str_replace( ',', '.', $_POST['_msrp_'.$loop] ) ) ) );
}

// Frontend Variation - Refundable Deposit display
add_filter( 'woocommerce_available_variation', 'display_variation_msrp', 10, 3 );
function display_variation_msrp( $data, $product, $variation ) {

    if( $msrp = $variation->get_meta('_msrp') ) {
        $data['price_html'] = '<div class="woocommerce_msrp">' . __( 'Refundable Deposit: ', 'woocommerce' ) .
        '<span class="msrp-price">' . wc_price( $msrp ) . '</span></div>' . $data['price_html'];
    }

    return $data;
}

我已在我要在购物车中显示价格的下方添加了图片。 请单击超链接以查看下面的图像。

Also I need price to be displayed and calculated in cart page and in total

And this is second image for reference.

0 个答案:

没有答案