Skip to content

Instantly share code, notes, and snippets.

@manchumahara
Created December 3, 2014 09:14
Show Gist options
  • Save manchumahara/2d97d7f8dd1e86072fe9 to your computer and use it in GitHub Desktop.
Save manchumahara/2d97d7f8dd1e86072fe9 to your computer and use it in GitHub Desktop.
//usages [add_to_cart_variable]
add_shortcode('add_to_cart_variable', 'add_to_cart_variable_function');
function add_to_cart_variable_function(){
global $product;
// Enqueue variation scripts
wp_enqueue_script( 'wc-add-to-cart-variation' );
ob_start();
// Load the template
wc_get_template( 'single-product/add-to-cart/variable.php', array(
'available_variations' => $product->get_available_variations(),
'attributes' => $product->get_variation_attributes(),
'selected_attributes' => $product->get_variation_default_attributes()
) );
$output = ob_get_contents();
ob_clean();
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment