简体   繁体   English

如何在 woocommerce 中的购物车数量旁边添加文本

[英]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.

相关问题 Woocommerce - 如何将数量传递到“添加到购物车”按钮 - Woocommerce - How to pass quantity into Add to cart button 如果数量增加,则使用jQuery更改WooCommerce的“添加到购物车”按钮文本 - WooCommerce Add To Cart Button text change using jQuery if Quantity increase 如何根据商品数量在购物车中为woocommerce添加消息 - How to add a message in cart for woocommerce based on item quantity 将数量选择添加到 woocommerce 购物车小部件 - add quantity select to woocommerce shopping cart widget 自定义添加到购物车按钮,将多个产品添加到购物车中,数量:woocommerce - Custom add to cart button to add multiple product into cart with quantity :woocommerce 设置自定义添加到购物车默认数量(Woocommerce 购物车页面除外) - Set custom Add to cart default quantity except on Woocommerce cart page 如何从WooCommerce中的购物车页面中删除数量 - How to remove quantity from cart page in WooCommerce 如何查看woocommerce购物车中的商品数量 - how to check the quantity of products in the woocommerce cart 如何更改woocommerce中购物车项目数量的设计? - How to change the design for cart item quantity in woocommerce? 如何在 WooCommerce 中的“查看购物车”按钮旁边添加“继续购物”按钮? - How to add "Continue Shopping" button next to "View Cart" button in WooCommerce?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM