Created
September 16, 2016 16:22
-
-
Save michelve/cf4d11fe391fed8a26942ec8f89922aa to your computer and use it in GitHub Desktop.
add variable product to cart woocommerce
This file contains 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 | |
// 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