{"id":437,"date":"2018-09-11T17:54:33","date_gmt":"2018-09-11T17:54:33","guid":{"rendered":"https:\/\/demos.welaunch.io\/woocommerce-attribute-images\/?post_type=faq&#038;p=437"},"modified":"2020-06-20T12:28:41","modified_gmt":"2020-06-20T10:28:41","slug":"woocommerce-subscriptions-support","status":"publish","type":"faq","link":"https:\/\/www.welaunch.io\/en\/knowledge-base\/faq\/woocommerce-subscriptions-support\/","title":{"rendered":"WooCommerce Subscriptions Plugin Support"},"content":{"rendered":"<p>In order to support the WooCommerce Subscription plugin you need to create the following file in your child theme &gt; wp-content\/themes\/child-theme\/woocommerce\/single-product\/add-to-cart\/variable-subscription.php<\/p>\n<pre>&lt;?php\n\/**\n * Variable subscription product add to cart\n *\n * @author  Prospress\n * @package WooCommerce-Subscriptions\/Templates\n * @version 2.2.20\n *\/\nif ( ! defined( 'ABSPATH' ) ) {\n\texit;\n}\n\nglobal $product;\n\n$attribute_keys = array_keys( $attributes );\n$user_id = get_current_user_id();\n\ndo_action( 'woocommerce_before_add_to_cart_form' ); ?&gt;\n\n&lt;form class=\"variations_form cart\" method=\"post\" enctype='multipart\/form-data' data-product_id=\"&lt;?php echo absint( $product-&gt;get_id() ); ?&gt;\" data-product_variations=\"&lt;?php echo htmlspecialchars( wcs_json_encode( $available_variations ) ) ?&gt;\"&gt;\n\t&lt;?php do_action( 'woocommerce_before_variations_form' ); ?&gt;\n\n\t&lt;?php if ( empty( $available_variations ) &amp;&amp; false !== $available_variations ) : ?&gt;\n\t\t&lt;p class=\"stock out-of-stock\"&gt;&lt;?php esc_html_e( 'This product is currently out of stock and unavailable.', 'woocommerce-subscriptions' ); ?&gt;&lt;\/p&gt;\n\t&lt;?php else : ?&gt;\n\t\t&lt;?php if ( ! $product-&gt;is_purchasable() &amp;&amp; 0 != $user_id &amp;&amp; 'no' != wcs_get_product_limitation( $product ) &amp;&amp; wcs_is_product_limited_for_user( $product, $user_id ) ) : ?&gt;\n\t\t\t&lt;?php $resubscribe_link = wcs_get_users_resubscribe_link_for_product( $product-&gt;get_id() ); ?&gt;\n\t\t\t&lt;?php if ( ! empty( $resubscribe_link ) &amp;&amp; 'any' == wcs_get_product_limitation( $product ) &amp;&amp; wcs_user_has_subscription( $user_id, $product-&gt;get_id(), wcs_get_product_limitation( $product ) ) &amp;&amp; ! wcs_user_has_subscription( $user_id, $product-&gt;get_id(), 'active' ) &amp;&amp; ! wcs_user_has_subscription( $user_id, $product-&gt;get_id(), 'on-hold' ) ) : \/\/ customer has an inactive subscription, maybe offer the renewal button ?&gt;\n\t\t\t\t&lt;a href=\"&lt;?php echo esc_url( $resubscribe_link ); ?&gt;\" class=\"button product-resubscribe-link\"&gt;&lt;?php esc_html_e( 'Resubscribe', 'woocommerce-subscriptions' ); ?&gt;&lt;\/a&gt;\n\t\t\t&lt;?php else : ?&gt;\n\t\t\t\t&lt;p class=\"limited-subscription-notice notice\"&gt;&lt;?php esc_html_e( 'You have an active subscription to this product already.', 'woocommerce-subscriptions' ); ?&gt;&lt;\/p&gt;\n\t\t\t&lt;?php endif; ?&gt;\n\t\t&lt;?php else : ?&gt;\n\t\t\t&lt;table class=\"variations\" cellspacing=\"0\"&gt;\n\t\t\t\t&lt;tbody&gt;\n\t\t\t\t&lt;?php foreach ( $attributes as $attribute_name =&gt; $options ) : ?&gt;\n\t\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t\t&lt;td class=\"label\"&gt;&lt;label for=\"&lt;?php echo esc_attr( sanitize_title( $attribute_name ) ); ?&gt;\"&gt;&lt;?php echo esc_html( wc_attribute_label( $attribute_name ) ); ?&gt;&lt;\/label&gt;&lt;\/td&gt;\n\t\t\t\t\t\t&lt;td class=\"value\"&gt;\n\t\t\t\t\t\t\t&lt;?php\n\t\t\t\t\t\t\t$selected = isset( $_REQUEST ) ? wc_clean( $_REQUEST ) : $product-&gt;get_variation_default_attribute( $attribute_name );\n\t\t\t\t\t\t\t\t$images = array();\n\t\t\t\t\t\t\t\tforeach ($options as $option) {\n\t\t\t\t\t\t\t\t\t$term = get_term_by('slug', $option, $attribute_name);\n\t\t\t\t\t\t\t\t\t$image = apply_filters('woocommerce_attribute_value_image', esc_html( $term-&gt;name ), $term-&gt;term_id, true);\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tif(!empty($image)) {\n\t\t\t\t\t\t\t\t\t\t$images[] = '&lt;a href=\"#\" class=\"woocommerce-attribute-images-variable-option\" data-attribute-value=\"' . $term-&gt;slug . '\" data-attribute-name=\"' . $attribute_name . '\"&gt;' . $image . '&lt;\/a&gt;';\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif(!empty($images) &amp;&amp; count($images) == count($options)) {\n\t\t\t\t\t\t\t\t\techo '&lt;div class=\"woocommerce-attribute-images-variable-options\"&gt;';\n\t\t\t\t\t\t\t\t\t\techo implode(' ', $images);\n\t\t\t\t\t\t\t\t\techo '&lt;div class=\"clear\"&gt;&lt;\/div&gt;&lt;\/div&gt;';\n\t\t\t\t\t\t\t\t\techo '&lt;div style=\"display: none;\"&gt;';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\twc_dropdown_variation_attribute_options( array( 'options' =&gt; $options, 'attribute' =&gt; $attribute_name, 'product' =&gt; $product, 'selected' =&gt; $selected ) );\n\n\t\t\t\t\t\t\t\tif(!empty($images) &amp;&amp; count($images) == count($options)) {\n\t\t\t\t\t\t\t\t\techo '&lt;\/div&gt;';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\/\/ wc_dropdown_variation_attribute_options( array( 'options' =&gt; $options, 'attribute' =&gt; $attribute_name, 'product' =&gt; $product, 'selected' =&gt; $selected ) );\n\t\t\t\t\t\t\t\/\/ echo wp_kses( end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '&lt;a class=\"reset_variations\" href=\"#\"&gt;' . __( 'Clear', 'woocommerce-subscriptions' ) . '&lt;\/a&gt;' ) : '', array( 'a' =&gt; array( 'class' =&gt; array(), 'href' =&gt; array() ) ) );\n\t\t\t\t\t\t\t?&gt;\n\t\t\t\t\t\t&lt;\/td&gt;\n\t\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;?php endforeach;?&gt;\n\t\t\t\t&lt;\/tbody&gt;\n\t\t\t&lt;\/table&gt;\n\n\t\t\t&lt;?php\n\t\t\t\/**\n\t\t\t * Post WC 3.4 the woocommerce_before_add_to_cart_button hook is triggered by the callback @see woocommerce_single_variation_add_to_cart_button() hooked onto woocommerce_single_variation.\n\t\t\t *\/\n\t\t\tif ( WC_Subscriptions::is_woocommerce_pre( '3.4' ) ) {\n\t\t\t\tdo_action( 'woocommerce_before_add_to_cart_button' );\n\t\t\t}\n\t\t\t?&gt;\n\n\t\t\t&lt;div class=\"single_variation_wrap\"&gt;\n\t\t\t\t&lt;?php\n\t\t\t\t\/**\n\t\t\t\t * woocommerce_before_single_variation Hook.\n\t\t\t\t *\/\n\t\t\t\tdo_action( 'woocommerce_before_single_variation' );\n\n\t\t\t\t\/**\n\t\t\t\t * woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.\n\t\t\t\t * @since 2.4.0\n\t\t\t\t * @hooked woocommerce_single_variation - 10 Empty div for variation data.\n\t\t\t\t * @hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.\n\t\t\t\t *\/\n\t\t\t\tdo_action( 'woocommerce_single_variation' );\n\n\t\t\t\t\/**\n\t\t\t\t * woocommerce_after_single_variation Hook.\n\t\t\t\t *\/\n\t\t\t\tdo_action( 'woocommerce_after_single_variation' );\n\t\t\t\t?&gt;\n\t\t\t&lt;\/div&gt;\n\n\t\t\t&lt;?php do_action( 'woocommerce_after_add_to_cart_button' ); ?&gt;\n\t\t&lt;?php endif; ?&gt;\n\t&lt;?php endif; ?&gt;\n\n\t&lt;?php do_action( 'woocommerce_after_variations_form' ); ?&gt;\n&lt;\/form&gt;\n\n&lt;?php\ndo_action( 'woocommerce_after_add_to_cart_form' );\n\n<\/pre>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","product_cat":[],"class_list":["post-437","faq","type-faq","status-publish","hentry","faq_topics-attribute-images-filter-hooks"],"_links":{"self":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq\/437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq"}],"about":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/types\/faq"}],"author":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/comments?post=437"}],"version-history":[{"count":0,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq\/437\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/media?parent=437"}],"wp:term":[{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/product_cat?post=437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}