-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Request] Disable PayPal Smart buttons for specific product types #234
Comments
Seconded for me as the author of Mix and Match Products and Name Your Price. The ideal would be that the buttons can be dynamically modified to reflect the custom prices... but in the absence of that they need to be disabled. |
As a followup, I will note that the PayPal Express Checkout plugin had javascript triggers for enabling and disabling the buttons. So they could be dynamically disabled when the complex product type's configuration was invalid and re-enabled when valid. |
As another follow up :) it's not possible to conditionally filter |
Thanks for your feedback. We are looking into this and will get back with more details. |
@InpsydeNiklas I was looking at this again today. It appears that there's this code Is there a way we could get that same listener to fire on custom product types? Mix and Match already toggles the |
@InpsydeNiklas in the short term I have an idea on how to remove the buttons conditionally at least for most users, but can't figure out how to get the instance of the
|
You can do it by accessing the container like shown in #203 and getting the |
Thanks @AlexP11223. Showing the limits of my skill here, but I find the code you linked to is quite difficult to read for those of us used to the traditional way of writing plugins. The example seems to show how to add a new service, so I'm still very unclear how to fetch an existing service. |
inside |
What is |
You don't need to use this modular architecture for your plugin, you can just create a basic module and register it via Then its'
|
Another option might be if you added a hook with the woocommerce-paypal-payments/modules/ppcp-button/src/Assets/class-smartbutton.php Line 426 in 0afe6cd
then plugins can turn the buttons off. For quick testing:
for testing with Mix and Match Products or Product Bundles
That's going to be a lot simpler from my end and completely eliminates any need for modules or I'm noticing the need for something similar with the "pay later" link as well. Seems silly to show the messages on a single product page when the request buttons aren't visible: |
We should not need to require |
You probably don't need to require it in composer if this code executes only when our plugin is active, because there is no isolation of dependencies in WP and it would be loaded by our plugin already. |
You might be right, but I am prepared to admit your codebase is too advanced/modern for me. It doesn't look or behave like any other plugin I've ever seen. Most of my other integrations are way simpler. Something like the following where we have 1 filter/callback and check the product object to see if it supports PRB or not would be ideal:
PayPal is attaching the render hooks very early (on the Jason's team has resorted to using CSS to hide the buttons and I will probably have to do the same. |
My use case is slightly different but I think we need the same solution. On the site I'm working on we have a Minimum Order Value where checkout buttons are disabled unless MOV amount is met. I like the solution suggested by #353 And this seems similar to strategy (1) suggested in https://inpsyde.com/en/remove-wordpress-hooks/ for removing closures from hooks. Something that would allow me to add to my theme:
woud be a great help. So that I can write code like so:
Linked: https://wordpress.org/support/topic/programatically-disable-pp-button/#post-15245620 In my case I'd need the ability to disable a button in Mini Cart, Cart page, and Checkout page. |
Describe the feature/request
Our team, SomewhereWarm, is looking to add an integration between our plugins and the new PayPal Payments. Some of the extensions we develop are Product Bundles, Gift Cards, Composite Products and All Products for WooCommerce Subscriptions -- all are available on WooCommerce.com.
These 4 extensions allow customers to make configurations in the single product page that can result to
We have found that currently PayPal Smart buttons do not parse these prices/data correctly when they are clicked. Therefore, to prevent any issues we thought to add an integration that disables these buttons for specific product pages -- we used to have a similar integration for PayPal Checkout.
Taking a look at the code, we noticed that you are already hiding these buttons for specific product types, such as Grouped and External:
woocommerce-paypal-payments/modules/ppcp-button/src/Assets/class-smartbutton.php
Line 426 in 0afe6cd
Ideally, we would like to filter the return value of these two functions:
woocommerce-paypal-payments/modules/ppcp-button/src/Assets/class-smartbutton.php
Line 421 in 0afe6cd
woocommerce-paypal-payments/modules/ppcp-button/src/Assets/class-smartbutton.php
Line 439 in 0afe6cd
Do you think it is possible to add a filter there that has the
$product
object as an argument?So far, we have tried a couple of approaches to disable these buttons. However, none of them was robust or performant enough!
The first thing we tried was to remove this action:
woocommerce-paypal-payments/modules/ppcp-button/src/Assets/class-smartbutton.php
Line 336 in 0afe6cd
SmartButton
object.Another thing we tried was to use the
woocommerce_paypal_payments_single_product_renderer_hook
and return an empty string. However, the$product
object wasn't available at this point and runningwc_get_product()
on every page load wasn't a performant solution.In case there is any way to achieve what we are after without introducing new filters, please let us know! Thank you in advance!
The text was updated successfully, but these errors were encountered: