• Resolved steplab

    (@steplab)


    Hi,
    I need to repeat Add to cart button inside single product template.
    I have a custom paypal button displaing by another plugin, after default add to cart default button.
    Inside custom button code I can see:
    add_action('woocommerce_after_add_to_cart_button', array($this, 'buy_now_button'), 10);
    So the button is displaing inside ‘woocommerce_template_single_add_to_cart’ action.
    So tried this code:

    
    function repeat_paypal(){
    	echo 'Purchase now:';
    	do_action('woocommerce_template_single_add_to_cart');
    	}
    add_action( 'woocommerce_after_single_product_summary', 'repeat_paypal', 14);	
    

    Text Purchase now is displaing but the purchase button is not displaing.
    What is wrong? There is another way to display woocommerce_template_single_add_to_cart action?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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, 7 months ago by Dat Hoang.
    Thread Starter steplab

    (@steplab)

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Repeat PayPal Express Button on Product page’ is closed to new replies.