Created
January 24, 2021 12:24
-
-
Save mzdebo/76b7aeaf81b7d2f28f0b9a3d5182ae0a to your computer and use it in GitHub Desktop.
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
*/ https://rudrastyh.com/woocommerce/before-and-after-add-to-cart.html */ | |
// Before Add to Cart Button | |
add_action( 'woocommerce_before_add_to_cart_button', 'misha_before_add_to_cart_btn' ); | |
function misha_before_add_to_cart_btn(){ | |
echo 'Some custom text here'; | |
} | |
// After Add to Cart Button | |
add_action( 'woocommerce_after_add_to_cart_button', 'misha_after_add_to_cart_btn' ); | |
function misha_after_add_to_cart_btn(){ | |
echo 'Some custom text here'; | |
} | |
*/ notes | |
* 2 More Hooks | |
* But there also 2 more hooks which are very similar – woocommerce_before_add_to_cart_form and woocommerce_after_add_to_cart_form. | |
* The hook woocommerce_before_add_to_cart_form will be fired a little bit earlier that woocommerce_before_add_to_cart_button, before <form> tag. | |
* The hook woocommerce_after_add_to_cart_form will be fired a little bit later than woocommerce_after_add_to_cart_button, after the closing </form> tag. | |
*/ | |
// Before Add to Cart Form | |
add_action( 'woocommerce_before_add_to_cart_form', 'misha_before_add_to_cart_form' ); | |
function misha_before_add_to_cart_form(){ | |
echo 'Some custom text here'; | |
} | |
// After Add to Cart Form | |
add_action( 'woocommerce_after_add_to_cart_form', 'misha_after_add_to_cart_form' ); | |
function misha_after_add_to_cart_form(){ | |
echo 'Some custom text here'; | |
} | |
// On Shop / Product Category Pages | |
// before or after: woocommerce_loop_add_to_cart_link | |
add_filter( 'woocommerce_loop_add_to_cart_link', 'misha_before_after_btn', 10, 3 ); | |
function misha_before_after_btn( $add_to_cart_html, $product, $args ){ | |
$before = ''; // Some text or HTML here | |
$after = ''; // Add some text or HTML here as well | |
return $before . $add_to_cart_html . $after; | |
} | |
*/ notes | |
* $product | |
***** It is a product object – it could be WC_Product_Simple or WC_Product_Variable or even WC_Product_Subscription if you are using WooCommerce Subscriptions plugin. You can obtain $product->id from these objects for example. | |
* $args | |
***** It just contains button attributes like quantity, class names etc | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment