如果购物车有来自特定类别的产品,我会尝试自动添加优惠券代码。显示折扣金额后,必须在总计中更新价格。
但我看不到总数有任何变化,请帮助我。
我的代码:
add_action('wc_cart_product_subtotal' , 'getsubtotalc');
function getsubtotalc ($product_subtotal, $_product, $quantity, $object) {
if( is_cart() || is_checkout() ) {
global $woocommerce, $product;
global $total_qty;
/*$coupon_code = 'drawer';
if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;*/
foreach ( $woocommerce->cart->cart_contents as $product ) {
if( has_term( array('t-shirts-d','socks-d','joggers-d','boxers-d'), 'product_cat', $cart_item['product_id'] ) ){
$coupon_code = 'drawer';
if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code))) {
$woocommerce->show_messages();
}
echo '<div class="woocommerce_message"><strong>The number of Product in your order is greater than 10 so a 10% Discount has been Applied!</strong>
</div>';
} …Run Code Online (Sandbox Code Playgroud) 我们的 WooCommerce 网站有 2 种货币。主要货币是印度卢比,次要货币是美元(使用货币切换器)。我尝试以美元下订单,但 YITH 发票显示发票中的主要印度卢比符号。
我尝试更改为各种可用的货币切换器插件,但发票中的符号不会更改,它只是采用默认货币符号。
我什至尝试将 'get_woocommerce_currency_symbol()' 添加到货币参数数组到 YITH 函数。我需要帮助。使用的插件是 YITH Invoice ver: 1.3.11。
function yith_get_formatted_price ( $price, $args = array () ) {
extract ( apply_filters ( 'wc_price_args', wp_parse_args ( $args, array (
'ex_tax_label' => false,
'currency' => get_woocommerce_currency_symbol (),
'decimal_separator' => wc_get_price_decimal_separator (),
'thousand_separator' => wc_get_price_thousand_separator (),
'decimals' => wc_get_price_decimals (),
'price_format' => get_woocommerce_price_format (),
) ) ) );
$negative = $price < 0;
$price = apply_filters ( 'raw_woocommerce_price', floatval ( …Run Code Online (Sandbox Code Playgroud)