1 回答
TA贡献1777条经验 获得超3个赞
您可以通过以下方式确定产品类型
function sione_change_cart_item_name_and_price( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
// Loop through cart items
foreach ( $cart->get_cart() as $cart_item ) {
// Get an instance of the WC_Product object
$product = $cart_item['data'];
// Get product id
$product_id = $cart_item['product_id'];
if( $product->is_type( 'simple' )) {
echo 'Simple = ' . $product_id . '<br>';
} else {
echo 'Else = ' . $product_id . '<br>';
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'sione_change_cart_item_name_and_price', 10, 1 );
- 1 回答
- 0 关注
- 54 浏览
添加回答
举报