【问题标题】:Woocommerce - Need to charge extra for First Order (Subscription Joining Fee)Woocommerce - 首次订购需要额外收费(订阅加入费)
【发布时间】:2019-01-01 09:49:24
【问题描述】:

我正在使用最新版本的 Woocommerce 的 Wordpress 4.9.7。我不知道修改 wordpress/woocommerce 代码。

我与 Woocommerce 相关的要求是,每当一个人购买新产品时,他都需要支付额外的费用,称为加入费。不同产品的加盟费不同。每当客户第一次购买产品时,我如何在购物车和产品中添加此加盟费?

谢谢

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    试试这个代码

    function custom_add_cart_fee() {
       $customer_orders = get_posts( array(
            'numberposts' => -1,
            'meta_key'    => '_customer_user',
            'meta_value'  => get_current_user_id(),
            'post_type'   => 'shop_order', // WC orders post type
            'post_status' => 'wc-completed' // Only orders with status "completed"
        ) );
        // Count number of orders
        $count = count( $customer_orders );
    
        if ( $count == 0 ) 
        {
             WC()->cart->add_fee( __( 'Joining Fee', 'your-plugin'), 100 );
        }
    
    }
    add_action( 'woocommerce_before_calculate_totals', 'custom_add_cart_fee' );
    

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-03
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多