WooCommerce Subscriptions - Check if a product is a subscription product

后端 未结 1 537
南笙
南笙 2021-01-15 04:51

I\'d like to know how to determine if a given WC_Product object $product is a subscription product or not.

相关标签:
1条回答
  • 2021-01-15 05:40

    You can use their helper function which is probably the most complete:

    if( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
        return TRUE;
    } else {
        return FALSE;
    }
    

    Or you could also use WooCommerce's $product->is_type( $type ) check.

    0 讨论(0)
提交回复
热议问题