Skip to content
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

Extend plugin modification options #203

Merged
merged 15 commits into from
Aug 9, 2021

Conversation

strangerkir
Copy link
Contributor

@strangerkir strangerkir commented Jul 26, 2021

Description

  1. Add filters to change hook PayPal buttons and Pay Later messages will be rendered on.
  2. Add filter to allow adding custom modules to the plugin or removing existing ones.

Added filters list for buttons and message position (for fixing the issue with the Germanized plugin these hooks should be enough):

  • woocommerce_paypal_payments_checkout_button_renderer_hook,
  • woocommerce_paypal_payments_checkout_dcc_renderer_hook,
  • woocommerce_paypal_payments_pay_order_dcc_renderer_hook,
  • woocommerce_paypal_payments_proceed_to_checkout_button_renderer_hook,
  • woocommerce_paypal_payments_mini_cart_button_renderer_hook,
  • woocommerce_paypal_payments_single_product_renderer_hook.

Added filter for custom modules (for more advanced extending, adding custom features, etc.):

  • woocommerce_paypal_payments_modules

Steps to test:

  1. Make sure buttons are rendered as they should.
  2. Create the simplest possible plugin, and use a filter to render buttons or message at another WC hook.
  3. In the test plugin add a custom module, try to extend (override) a service from the WooCommerce PayPal Payments plugin or just access the container.

Documentation

  • This PR needs documentation (has the "Documentation" label).

Changelog entry

  • Add - Filters to move PayPal buttons and Pay Later messages.
  • Add - Filter to modify plugin modules list.

Closes #209 (see added filters section above, the filter to use is woocommerce_paypal_payments_modules). Also, see the section below.

Adding modules and accessing the plugin container

To access the container from outside, add your module using a filter provided above. Inside your module, you will be able to access and extend/modify the container. This is a simplified example:

//composer.json

{
  "name": "vendor_name/test-plugin",
  "description": "description",
  "minimum-stability": "stable",
  "require": {
    "dhii/module-interface": "0.3.x-dev"
  }
}

//your-plugin.php

$module = new class implements Dhii\Modular\Module\ModuleInterface{
	public function setup(): ServiceProviderInterface
	{
		return new ServiceProvider(
			[], //place here your services you want to add to container,
                        [] // place here your extensions to replace existing container services (see links below for more details).
		);
	}
	
	public function run(ContainerInterface $c): void
	{
                //here you can get the container instance and do something with it.
		add_action('admin_notices', function() use ($c){
			$c->get('admin-notices.renderer')->render();
		});
	}
};

add_filter('woocommerce_paypal_payments_modules', function($modules) use ($module) {
	array_push($modules, $module);
	
	return $modules;
});

See https://github.com/container-interop/service-provider and https://github.com/Dhii/module-interface for more details.

@strangerkir strangerkir requested a review from Dinamiko July 27, 2021 11:11
@strangerkir strangerkir marked this pull request as ready for review July 27, 2021 11:11
Copy link
Contributor

@Dinamiko Dinamiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great solution, good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to access $container
2 participants