【问题标题】:Change "Email" label based on product category in Woocommerce checkout根据 Woocommerce 结帐中的产品类别更改“电子邮件”标签
【发布时间】:2018-11-06 09:07:55
【问题描述】:

我正在尝试在结帐页面上为特定类别显示不同的“电子邮件标签”。

例如: 我在网站上销售礼品卡,因此我想将“电子邮件”字段重命名为“收件人电子邮件”,但此特定标签仅对“礼品”产品类别可见。

我找不到适用于这个特定解决方案的任何 WooCommerce 功能。任何帮助将不胜感激。

【问题讨论】:

    标签: php wordpress woocommerce checkout custom-taxonomy


    【解决方案1】:

    更新:如果“礼品”产品类别在购物车中,以下将更改帐单电子邮件标签:

    // Change billing email label if "Gift" product category is in cart
    add_filter( 'woocommerce_checkout_fields', 'change_billing_email_label' );
    function change_billing_email_label($fields){
        foreach(WC()->cart->get_cart() as $cart_item) {
            if( has_term( "Gifts", "product_cat", $cart_item["product_id"] ) ){
                $fields['billing']['billing_email']['label'] = __("Recipient Email", "woocommerce");
                break;
            }
        }
    
        return $fields;
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。它应该可以工作。

    【讨论】:

      【解决方案2】:

      感谢“LoicTheAztec”。

      我只需要从他的代码中更改以下代码行

      foreach(WC()->cart->get_cart() => $cart_item) {
      

      有了这个

      foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
      

      【讨论】:

        猜你喜欢
        • 2021-04-21
        • 1970-01-01
        • 1970-01-01
        • 2019-02-04
        • 1970-01-01
        • 2021-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多