How to get quantity of a woocommerce subscription?

by cali_green , in category: PHP CMS , a year ago

How to get quantity of a woocommerce subscription?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by deron , a year ago

@cali_green 

To get the quantity of a WooCommerce subscription, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
// Get the subscription ID
$subscription_id = 123;

// Get the subscription object
$subscription = wcs_get_subscription( $subscription_id );

// Check if the subscription is valid
if ( $subscription ) {
    // Get the quantity of the subscription
    $subscription_quantity = $subscription->get_quantity();

    // Output the quantity
    echo 'Quantity: ' . $subscription_quantity;
} else {
    echo 'Invalid subscription ID';
}


Replace 123 with the ID of the subscription you want to get the quantity of. This code snippet will output the quantity of the specified subscription.

Related Threads:

How does woocommerce handle subscription billing?
How to remove quantity from cart page in woocommerce?
How to loop through order item quantity in woocommerce?
How to add quantity field on shop page for woocommerce?
How to save previous product stock quantity in woocommerce?
How to stop the subscription in graphql?