我最近从woocommerce 2.7跳到了3.1,我对woocommerce_before_calculate_totals
钩住下面的功能。
function calculate_embossing_fee( $cart_object ) {
if( !WC()->session->__isset( "reload_checkout" )) {
/* Gift wrap price */
$additionalPrice = 5;
foreach ( $cart_object->cart_contents as $key => $value ) {
if( isset( $value["embossing_fee"] ) ) {
$orgPrice = floatval( $value[\'data\']->price );
$discPrice = $orgPrice + $additionalPrice;
$value[\'data\']->set_price($discPrice);
}
}
}
}
add_action( \'woocommerce_before_calculate_totals\', \'calculate_embossing_fee\', 99 );
有人知道为什么这会抛出一个错误以及我如何解决它吗?
我得到的错误是:确定:
Notice: price was called incorrectly. Product properties should not be accessed directly. Backtrace: require(\'wp-blog-header.php\'), require_once(\'wp-includes/template-loader.php\'), include(\'/themes/bdop/page.php\'), the_content, apply_filters(\'the_content\'), WP_Hook->apply_filters, call_user_func_array, do_shortcode, preg_replace_callback, do_shortcode_tag, call_user_func, WC_Shortcodes::cart, WC_Shortcodes::shortcode_wrapper, call_user_func, WC_Shortcode_Cart::output, WC_Cart->calculate_totals, do_action(\'woocommerce_before_calculate_totals\'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, calculate_embossing_fee, WC_Abstract_Legacy_Product->__get, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 3.0.) in /Applications/MAMP/htdocs/bdop/wp-includes/functions.php on line 4139