Created
September 5, 2017 02:51
-
-
Save jamesgol/33eea04760b47c8bcd62132ac7108904 to your computer and use it in GitHub Desktop.
Allow WooCommerce variations to be added to cart via URL
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
add_action( 'init', 'woo_add_to_cart_fixup' ); | |
function woo_add_to_cart_fixup() { | |
// Duplicate WooCommerce variation attributes from $_GET to $_POST because WC_Form_Handler->add_to_cart_handler_variable only looks in $_POST | |
if ( isset( $_GET, $_GET['add-to-cart'] ) ) { | |
foreach ( $_GET as $key => $value ) { | |
if ( false !== strpos( $key, 'attribute' ) ) { | |
$_POST[ $key ] = $value; | |
} | |
} | |
} | |
} |
This will be unnecessary with the next WooCommerce release. PR was just merged in woocommerce/woocommerce#16715
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allows a HTTP GET request to add to cart like: http://woodev.local/cart/?add-to-cart=10&attribute_color=orange&attribute_size=large