【发布时间】:2020-04-26 14:06:03
【问题描述】:
我想要特定 woocommerce 类别的块价格,现在仅适用于我的代码的所有类别 woocommerce。我的类别名称是:股票。我只想用于这个类别。
我希望用户如果购买股票类别必须至少购买 1200。
// Set a minimum dollar amount per order
add_action( 'woocommerce_check_cart_items', 'spyr_set_min_total' );
function spyr_set_min_total() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set minimum cart total
$minimum_cart_total = 1200;
// Total we are going to be using for the Math
// This is before taxes and shipping charges
$total = WC()->cart->subtotal;
// Compare values and add an error is Cart's total
// happens to be less than the minimum required before checking out.
// Will display a message along the lines of
// A Minimum of 10 USD is required before checking out. (Cont. below)
// Current cart total: 6 USD
if( $total <= $minimum_cart_total ) {
// Display our error message
wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>'
.'<br />Current cart\'s total: %s %s',
$minimum_cart_total,
get_option( 'woocommerce_currency'),
$total,
get_option( 'woocommerce_currency') ),
'error' );
}
}
}
【问题讨论】:
-
你能告诉我
stock的类别ID吗? -
是的,分类id是:1441
-
它有父类吗?
-
不,没什么。这是主要类别。
-
好的,那就试试我的回答吧!我正在发布..
标签: php wordpress woocommerce