[英]How to add text next to the quantity on the cart in woocommerce
I'm not a developer, but i'm trying like heck.我不是开发人员,但我正在努力。 I have two product tags.
我有两个产品标签。 One product sold by "each", tag#1, the other product is sold by sq ft, tag#2.
一种产品按“每个”销售,标签#1,另一种产品按平方英尺销售,标签#2。 I'm trying to display "each" or "sq ft" next to or under the quantity box on the cart page.
我正在尝试在购物车页面的数量框旁边或下方显示“每个”或“平方英尺”。 I've been able to add it next to product prices, but I can't for the life of me get this displayed next to quantity input only on the cart page.
我已经能够将其添加到产品价格旁边,但我无法在我的一生中仅将其显示在购物车页面上的数量输入旁边。 Any help from one of you experts is greatly appreciated!
非常感谢您的一位专家的任何帮助!
This section works fine.这部分工作正常。
add_filter( 'woocommerce_get_price_html', 'mto_text_after_price' );
function mto_text_after_price($price){
if( !has_term( 'clearance', 'product_tag')) {
$text_to_add_after_price = ' each '; //change text in bracket to your preferred text
}
if( !has_term( 'cove-base', 'product_tag')) {
$text_to_add_after_price = ' Sq Ft '; //change text in bracket to your preferred text
}
return $price . $text_to_add_after_price;
}
This section does not on the cart page...and excuse my mess此部分不在购物车页面上......请原谅我的混乱
add_action('woocommerce_after_quantity_input_field', 'wc_text_after_quantity');
function wc_text_after_quantity() {
//if ( is_cart() && is_product() && !has_term( 'clearance', 'product_tag' ) ) {
// echo '<br>Each';
// }
if ( is_cart() && has_term( 'cove-base', 'product_tag' ) ) {
echo '<br>Each';
}
elseif ( is_cart() && has_term( 'clearance', 'product_tag' ) ) {
echo '<br>Sq Ft';
}
// if( is_cart() && !has_term( 'clearance', 'product_tag')) {
//echo '<br>Each';
//}
// if( is_cart() && !has_term( 'cove-base', 'product_tag')) {
// echo '<br>Sq Ft';
// }
//foreach( WC()->cart->get_cart() as $cart_item ){
// For product Tags (term IDs, term slugs or term names)
// if( !has_term('cove-base', 'product_tag', $cart_item['product_id'] ) ) {
// echo '<br>Sq Ft';
//}
//}
}
/* this may help you, not sure but you can figure out / / it may be relate to your stuff */ /* 这可能对你有帮助,不确定但你可以弄清楚//它可能与你的东西有关 */
add_action( 'woocommerce_before_add_to_cart_quantity', 'qty_front_add_cart' );
function qty_front_add_cart() {
echo '<div class="qty">Sq Ft</div>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.