<?php | |
/** | |
* Only copy opening php if needed | |
* | |
* Adds a "subscribe and save" box after the add to cart button | |
* Only added if `subscribe_save_id` field is set | |
*/ | |
function sww_add_subscribe_save_to_product() { | |
global $product; // get the current product to see if it has a 'subscribe and save' | |
$subscription_id = (int) get_post_meta( $product->id, 'subscribe_save_id', true ); | |
// only proceed if we do have a 'subscribe and save' | |
if ( $subscription_id ) { | |
$subscription = get_post( $subscription_id ); | |
// output our subscription short description + the add to cart shortcode | |
echo wp_kses_post( $subscription->post_excerpt ); | |
echo do_shortcode( '[add_to_cart id="' . $subscription_id . '"]' ); | |
} | |
} | |
add_action( 'woocommerce_single_product_summary', 'sww_add_subscribe_save_to_product', 31 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment