admin管理员组文章数量:1290135
I want to program the Add to Cart button, on a product page, so when the customer press on it, it skips the Cart & Checkout pages and send him directly to the PayPal payment gateway.
Not spending time on the Cart page, nor filling details on the Checkout page.
How can I do this?
I want to program the Add to Cart button, on a product page, so when the customer press on it, it skips the Cart & Checkout pages and send him directly to the PayPal payment gateway.
Not spending time on the Cart page, nor filling details on the Checkout page.
How can I do this?
2 Answers
Reset to default 2A solution can be found in the function woocommerce_add_to_cart_action
. We have to chain two filters. In the first, we check for the product ID, if it's one of a list we add the redirect.
add_action( 'woocommerce_add_to_cart_validation', 'check_ids_wpse_119466', 10, 3 );
function check_ids_wpse_119466( $true, $product_id, $quantity )
{
# Not our products, bail out
# Adjust the products IDs
if( !in_array( $product_id, array( 1306,1303 ) ) ) // <------ ADJUST LIST
return $true;
add_filter( 'add_to_cart_redirect', 'redirect_wpse_119466' );
add_filter( 'allowed_redirect_hosts', 'whitelist_wpse_119466' );
return $true;
}
function redirect_wpse_119466( $url )
{
return 'http://paypal';
}
function whitelist_wpse_119466( $hosts )
{
$hosts[] = 'paypal';
return $hosts;
}
There's a third filter that we need to add, and it tells WordPress that PayPal is a safe host to redirect.
Yes, the list of products has to be made by hand. Or add an option somewhere in the theme, in a plugin or even WordPress settings to put this values (with a multiple selection field).
Related: Where do I put the code snippets I found here or somewhere else on the web?
create a paypal smart button(buy or add to cart) from paypal and paste the HTML code in the website (in HTML )..on click, it will redirect to Paypal page for login and payment processing.its a simple process.
本文标签: pluginsMaking the 39add to cart39 button redirect to PayPal
版权声明:本文标题:plugins - Making the 'add to cart' button redirect to PayPal 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741494007a2381750.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论