Created
October 4, 2022 22:29
-
-
Save growdev/d3b5b14b8b8e2156d793acd4725f48b1 to your computer and use it in GitHub Desktop.
Only show Add to Existing on some products.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Form used for add to existing subscription from the single product page. | |
* | |
* @author Shop Plugins | |
* @category WooCommerce Subscriptions/Templates | |
* @version 2.0.1 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly | |
} | |
if ( ! $product->is_purchasable() ) { | |
return; | |
} | |
if ( ! in_array( $product->get_id(), array( 17 ) ) ){ | |
return; | |
} | |
?> | |
<form action="#" method="POST" class="jgtb-add-to-subscription"> | |
<label for="jgtb_add_to_existing"><?php esc_html_e( 'Add to your subscription', 'jg-toolbox' ); ?></label> | |
<select name="jgtb_add_to_existing_subscription" id="jgtb_add_to_existing"> | |
<option value="null"> | |
<?php echo esc_html_x( '-- Select an existing subscription --', 'default option in dropdown in add to existing subscription template', 'jg-toolbox' ); ?> | |
</option> | |
<?php | |
foreach ( $subscriptions as $subscription ) { | |
echo wp_kses( sprintf( '<option value="%s">%s</option>', $subscription->get_id(), Javorszky\Toolbox\Utilities\generate_option_text( $subscription ) ), array( 'option' => array( 'value' => array() ) ) ); | |
} | |
unset( $subscription ); | |
?> | |
</select> | |
<?php | |
foreach ( $subscriptions as $subscription ) { | |
$items_string = Javorszky\Toolbox\Utilities\generate_nonce_on_items( $subscription ); | |
wp_nonce_field( 'add_to_subscription_' . $items_string, 'jgtbwpnonce_' . $subscription->get_id(), false ); | |
} | |
?> | |
<input type="hidden" name="ats_quantity" value="0"> | |
<input type="hidden" name="ats_product_id" value="<?php echo esc_attr( $product->get_id() ); ?>"> | |
<input type="hidden" name="ats_variation_id" value="0"> | |
<input type="hidden" name="ats_variation_attributes" value=""> | |
<button type="submit" name="add-to-subscription" disabled="disabled" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt"> | |
<?php echo esc_html_x( 'Add to subscription', 'Text on button for add to existing subscription functionality', 'jg-toolbox' ); ?> | |
</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment