Skip to content

Instantly share code, notes, and snippets.

@michelve
Created September 16, 2016 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelve/cf4d11fe391fed8a26942ec8f89922aa to your computer and use it in GitHub Desktop.
Save michelve/cf4d11fe391fed8a26942ec8f89922aa to your computer and use it in GitHub Desktop.
add variable product to cart woocommerce
<?php
// Get the WooCommerce Shop URL
$store_url = get_site_url();
// Action to perform: lets add product to cart
$action = "/?add-to-cart=";
// The product ID that we want to add.
$productID = "375";
// Variation parameter name
$variation_param = "&variation_id=";
// Product variation ID
$variation_id = "377";
//Product variation name
$attribute_name = "&attribute_pa_pro-subscription=";
// The product attribute name value
$attribute_value = "12-months-subscription";
// full link to add a product
define('ADD_PRODUCT_TO_CART', $store_url.$action.$productID.$variation_param.$variation_id.$attribute_name.$attribute_value);
?>
<a id="buy" href="<?php echo ADD_PRODUCT_TO_CART; ?>">Buy this!</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment