Hi,
It seems that you’re trying to duplicate “Add to Cart” button from this line https://github.com/woocommerce/woocommerce/blob/0f731d9c3f9a7e75ac5d8ebd9e6ea646165494c1/includes/wc-template-hooks.php#L175:
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
1, If so, you would do something like this for your code:
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_add_to_cart', 14 );
2, Otherwise, if you still want to use your code, you should call the woocommerce_template_single_add_to_cart
function directly:
function repeat_paypal(){
echo 'Purchase now:';
woocommerce_template_single_add_to_cart();
}
add_action( 'woocommerce_after_single_product_summary', 'repeat_paypal', 14);
Your code did not work because there is no add_action
for woocommerce_template_single_add_to_cart
.
-
This reply was modified 5 years ago by Dat Hoang.
Ok thanks, if I use solution 1 or 2 add to cart button is showing. But is not showing the custom paypal express button (by PayPal for Woocommerce) if you don’t know why I still waiting answers by the other plugin.
So now I can repeat the add to cart button for example after tabs:
add_action( 'woocommerce_after_single_product', 'woocommerce_template_single_add_to_cart', 14 );
I can repeat the button with this code, maybe using the shortcode inside product description :
function repeat_paypal(){
echo 'Purchase now:';
woocommerce_template_single_add_to_cart();
}
add_shortcode( 'purchase_product', 'repeat_paypal');
I can repeat the add to cart button inside a promotional page of the product?
Maybe like this?:
function repeat_paypal($atts){
global $product;
$product = wc_get_product($atts['product_id']);
echo 'Purchase now:';
woocommerce_template_single_add_to_cart();
}
add_shortcode( 'purchase_product', 'repeat_paypal');
how to pass product id to woocommerce_template_single_add_to_cart function?
Better like this?:
function repeat_paypal($atts){
global $product;
$product = wc_get_product($atts['product_id']);
echo 'Purchase now:';
woocommerce_simple_add_to_cart();
}
add_shortcode( 'purchase_product', 'repeat_paypal');
Hi,
I can repeat the add to cart button inside a promotional page of the product?
For what you need, I think you just need to use the built-in [add_to_cart]
shortcode.
* https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-15