【问题标题】:Woocommerce add to cart monly or yearly paymentWoocommerce 按月或按年付款添加到购物车
【发布时间】:2017-07-12 07:44:48
【问题描述】:

我是订阅付款的新手,需要有关订阅付款的帮助。我在用 WC()->cart->add_to_cart($parent_id); 用于将产品添加到购物车。 我如何将产品添加到购物车以按月或按年定期付款。 我应该发送什么参数?

WC()->cart->add_to_cart($parent_id, 'yearly' ); 还是什么?

【问题讨论】:

  • 您必须先创建订阅产品或订阅。然后我想您实际上可以使用您的代码添加它。您可以阅读有关订阅的更多信息here
  • 我已经创建了订阅产品
  • 我只是想知道我应该在这个函数中添加订阅期的代码还是如果有其他代码? WC()->cart->add_to_cart($parent_id, 'yearly' );或 WC()->cart->add_to_cart( $parent_id, 'monthly' );还是什么?
  • 订阅期限、时长和设置在订阅产品中设置。请注意,订阅不是常规的 Woocommerce 产品。您必须已安装订阅扩展。然后您可以使用 add_to_cart 添加订阅产品。
  • 我已经购买并安装了订阅扩展。现在我正在做自定义更改,我需要将产品添加到购物车,产品 ID 及其订阅期间隔每月或每年...

标签: wordpress


【解决方案1】:

订阅间隔在产品页面中设置。

如果您希望订阅具有不同的时间间隔并希望从语法上选择它们,您必须创建一个可变订阅并更改每个变体中的时间段。

然后,当您将产品添加到购物车时,您可以选择要添加的变体

add_to_cart( $product_id, $quantity, $variation_id);

这是 add_to_cart 函数的所有可用参数:

    /**
     * Add a product to the cart.
     *
     * @param int $product_id contains the id of the product to add to the cart
     * @param int $quantity contains the quantity of the item to add
     * @param int $variation_id
     * @param array $variation attribute values
     * @param array $cart_item_data extra cart item data we want to pass into the item
     * @return string|bool $cart_item_key
     */
    public function add_to_cart( $product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array() ) {
        [...]
    }

查看Woocommerce Subscriptions FAQ中的完整文档

【讨论】:

    猜你喜欢
    • 2018-10-30
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 2015-01-03
    • 1970-01-01
    相关资源
    最近更新 更多