Created
September 4, 2019 14:48
-
-
Save linkdigitaluk/19e747d7f73968ba91d0aca5865e0918 to your computer and use it in GitHub Desktop.
[Custom Add to cart on shop/category page] #graveyard
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
function get_woo_variations() { | |
global $product; | |
return $product->get_available_variations(); | |
} | |
add_action( 'woocommerce_after_shop_loop_item', 'amend_add_to_cart_buttons', 1 ); | |
function amend_add_to_cart_buttons() { | |
if( is_product_category() || is_shop()) { | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); | |
add_action( 'woocommerce_after_shop_loop_item', 'link_shop_add_to_cart' ); | |
} | |
} | |
function link_shop_add_to_cart() { | |
global $product; | |
if ( ! $product->is_type( 'variable' ) ) { | |
woocommerce_template_loop_add_to_cart(); | |
return; | |
} | |
$variations = get_woo_variations(); ?> | |
<p>Select an | |
<select> | |
<option value="" selected disabled hidden>Select an option</option> | |
<?php foreach ($variations as $variation) : ?> | |
<option value="<?php echo $variation['variation_id']; ?>"><?php echo $variation['attributes']['attribute_options']; ?></option> | |
<?php endforeach; ?> | |
</select> | |
<?php } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment