{"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&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":"
In order to support the WooCommerce Subscription plugin you need to create the following file in your child theme > wp-content\/themes\/child-theme\/woocommerce\/single-product\/add-to-cart\/variable-subscription.php<\/p>\n
<?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' ); ?>\n\n<form class=\"variations_form cart\" method=\"post\" enctype='multipart\/form-data' data-product_id=\"<?php echo absint( $product->get_id() ); ?>\" data-product_variations=\"<?php echo htmlspecialchars( wcs_json_encode( $available_variations ) ) ?>\">\n\t<?php do_action( 'woocommerce_before_variations_form' ); ?>\n\n\t<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>\n\t\t<p class=\"stock out-of-stock\"><?php esc_html_e( 'This product is currently out of stock and unavailable.', 'woocommerce-subscriptions' ); ?><\/p>\n\t<?php else : ?>\n\t\t<?php if ( ! $product->is_purchasable() && 0 != $user_id && 'no' != wcs_get_product_limitation( $product ) && wcs_is_product_limited_for_user( $product, $user_id ) ) : ?>\n\t\t\t<?php $resubscribe_link = wcs_get_users_resubscribe_link_for_product( $product->get_id() ); ?>\n\t\t\t<?php if ( ! empty( $resubscribe_link ) && 'any' == wcs_get_product_limitation( $product ) && wcs_user_has_subscription( $user_id, $product->get_id(), wcs_get_product_limitation( $product ) ) && ! wcs_user_has_subscription( $user_id, $product->get_id(), 'active' ) && ! wcs_user_has_subscription( $user_id, $product->get_id(), 'on-hold' ) ) : \/\/ customer has an inactive subscription, maybe offer the renewal button ?>\n\t\t\t\t<a href=\"<?php echo esc_url( $resubscribe_link ); ?>\" class=\"button product-resubscribe-link\"><?php esc_html_e( 'Resubscribe', 'woocommerce-subscriptions' ); ?><\/a>\n\t\t\t<?php else : ?>\n\t\t\t\t<p class=\"limited-subscription-notice notice\"><?php esc_html_e( 'You have an active subscription to this product already.', 'woocommerce-subscriptions' ); ?><\/p>\n\t\t\t<?php endif; ?>\n\t\t<?php else : ?>\n\t\t\t<table class=\"variations\" cellspacing=\"0\">\n\t\t\t\t<tbody>\n\t\t\t\t<?php foreach ( $attributes as $attribute_name => $options ) : ?>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td class=\"label\"><label for=\"<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>\"><?php echo esc_html( wc_attribute_label( $attribute_name ) ); ?><\/label><\/td>\n\t\t\t\t\t\t<td class=\"value\">\n\t\t\t\t\t\t\t<?php\n\t\t\t\t\t\t\t$selected = isset( $_REQUEST ) ? wc_clean( $_REQUEST ) : $product->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->name ), $term->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[] = '<a href=\"#\" class=\"woocommerce-attribute-images-variable-option\" data-attribute-value=\"' . $term->slug . '\" data-attribute-name=\"' . $attribute_name . '\">' . $image . '<\/a>';\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) && count($images) == count($options)) {\n\t\t\t\t\t\t\t\t\techo '<div class=\"woocommerce-attribute-images-variable-options\">';\n\t\t\t\t\t\t\t\t\t\techo implode(' ', $images);\n\t\t\t\t\t\t\t\t\techo '<div class=\"clear\"><\/div><\/div>';\n\t\t\t\t\t\t\t\t\techo '<div style=\"display: none;\">';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\twc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );\n\n\t\t\t\t\t\t\t\tif(!empty($images) && count($images) == count($options)) {\n\t\t\t\t\t\t\t\t\techo '<\/div>';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\/\/ wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );\n\t\t\t\t\t\t\t\/\/ echo wp_kses( end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '<a class=\"reset_variations\" href=\"#\">' . __( 'Clear', 'woocommerce-subscriptions' ) . '<\/a>' ) : '', array( 'a' => array( 'class' => array(), 'href' => array() ) ) );\n\t\t\t\t\t\t\t?>\n\t\t\t\t\t\t<\/td>\n\t\t\t\t\t<\/tr>\n\t\t\t\t<?php endforeach;?>\n\t\t\t\t<\/tbody>\n\t\t\t<\/table>\n\n\t\t\t<?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?>\n\n\t\t\t<div class=\"single_variation_wrap\">\n\t\t\t\t<?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?>\n\t\t\t<\/div>\n\n\t\t\t<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>\n\t\t<?php endif; ?>\n\t<?php endif; ?>\n\n\t<?php do_action( 'woocommerce_after_variations_form' ); ?>\n<\/form>\n\n<?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}]}}