【问题标题】:Disable user profile update when data already exist after Woocommerce checkout在 Woocommerce 结帐后数据已存在时禁用用户配置文件更新
【发布时间】:2019-08-06 00:23:50
【问题描述】:

我有一个商店,用户在个人资料中注册了数据。在结帐页面中,可以更改自动填充的数据(拉动配置文件)。

我希望:例如,如果客户输入另一个地址或另一个电子邮件,这些数据将不会保存在配置文件中。

【问题讨论】:

    标签: php wordpress woocommerce checkout hook-woocommerce


    【解决方案1】:

    如果下订单时数据已经存在,以下将禁用更新用户配置文件(参见WC_Checkoutprocess_customer()方法source code

    add_filter( 'woocommerce_checkout_update_customer_data', 'checkout_update_customer_data_callback', 10, 2 );
    function checkout_update_customer_data_callback( $boolean, $checkout ) {
        if ( get_current_user_id() > 0 ) {
            $customer = new WC_Customer( get_current_user_id() );
            $first_name = $customer->get_first_name();
    
            // When customer data already exist, don't update it when an order is processed
            if ( ! empty( $first_name ) ) {
                return false;
            }
        }
        return $boolean;
    }
    

    代码进入活动子主题(或活动主题)的functions.php文件中。经过测试并且可以工作。

    相关:Disable woocommerce_checkout_update_customer_data

    【讨论】:

      猜你喜欢
      • 2013-07-22
      • 2017-05-19
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 2015-11-14
      • 2022-11-10
      • 2019-09-12
      相关资源
      最近更新 更多