Created
June 28, 2019 03:24
-
-
Save hirejordansmith/8580f3c94c1da68dee34da5ab75103f7 to your computer and use it in GitHub Desktop.
How to add a WooCommerce Quick Buy Link without a plugin
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 | |
// Outputs the button below the default Add to cart button on Single Product page | |
add_action('woocommerce_after_add_to_cart_button','hjs_add_quick_buy_link_single', 5); | |
function hjs_add_quick_buy_link_single() { ?> | |
<style> | |
.woocommerce div.product form.cart .button.quick-buy { | |
background: #f04e3d !important; | |
border-color: #f04e3d !important; | |
margin-left: 10px; | |
} | |
.woocommerce div.product form.cart .button.quick-buy:hover, | |
.woocommerce div.product form.cart .button.quick-buy:focus { | |
background: #e64135 !important; | |
border-color: #e64135 !important; | |
} | |
</style> | |
<a class="button quick-buy" href=<?php echo site_url('/checkout/?add-to-cart=' . $product_id ); ?>>Quick Buy</a> | |
<?php } | |
// Outputs the button below the default Add to cart button on Product Archive / Category pages | |
add_action( 'woocommerce_after_shop_loop_item', 'hjs_add_quick_buy_link_archive', 15 ); | |
function hjs_add_quick_buy_link_archive() { | |
global $product; | |
$product_id = $product->get_id(); | |
?> | |
<style> | |
.woocommerce ul.products li.product .button.quick-buy { | |
background: #f04e3d !important; | |
border-color: #f04e3d !important; | |
color: #fff !important; | |
} | |
.woocommerce ul.products li.product .button.quick-buy:hover, | |
.woocommerce ul.products li.product .button.quick-buy:focus { | |
background: #e64135 !important; | |
border-color: #e64135 !important; | |
color: #fff !important; | |
} | |
</style> | |
<a class="button quick-buy" href=<?php echo site_url('/checkout/?add-to-cart=' . $product->get_id() ); ?>>Quick Buy</a> | |
<?php } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment