Adding a receipt page on woocommerce - wordpress

I am developing a payment gateway for woocommerce.
I read many tutorial of how I can manage to do it but I can't figure out what this line of code mean:
add_action( 'woocommerce_receipt_paypal', array( $this, 'receipt_page' ) );
Especially, there is no function called woocommerce_receipt_paypal and how can I reproduce it in my plugin.

You have to replace
add_action( 'woocommerce_receipt_paypal', array( $this, 'receipt_page' ) );
with
add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'receipt_page' ) );
where id is the one you set in __construct() function.

Related

Woocommerce - remove scheduled email

I have a plugin which help me to book events. I have integrated a mail scheduler for reminder emails & feedback emails.
On confirmed booking emails are scheduled for reminder as well as feedback. I have both options to define it globally as well as individually to each event. This class is adding actions for the scheduled emails.
class WooEvent_Reminder_Email {
public function __construct()
{
add_filter( 'exc_mb_meta_boxes', array($this,'email_reminder_metadata') );
// Schedule the event when the order is completed.
add_action( 'woocommerce_order_status_completed', array( $this, 'remind_email' ), 10, 1 );
add_action( 'woocommerce_order_status_completed', array( $this, 'remind_email_fb' ), 11, 1 );
// Trigger the email.
add_action( 'wooevent_email_reminder', array( &$this, 'send_mail' ),10,4 );
add_action( 'wooevent_email_reminder_2', array( $this, 'send_mail' ),10,4 );
add_action( 'wooevent_email_reminder_3', array( $this, 'send_mail' ),10,4 );
add_action( 'wooevent_email_reminder_feedback', array( $this, 'send_mail_fb' ),10,3);
// send email to attendee
add_action( 'we_send_email_reminder', array( &$this, 'send_mail_attendee' ),10,1 );
}
Now, due to some reasons the event is not happening and I have created one more category for products "event-deactivated". If this category, I want to disable the event as well as want to remove all further email actions (i.e. no more notifications to the customer). For this objective, I am running this code:
add_filter('woocommerce_is_purchasable', 'nms3_catalog_mode_on_for_product', 10, 2 );
function nms3_catalog_mode_on_for_product( $is_purchasable, $product ) {
global $WooEvent_Reminder_Email;
if( has_term( 'seminar-deaktiviert', 'product_cat', $product->get_id() ) ) {
// you can set multiple conditions here
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Trigger the email.
remove_action( 'woocommerce_order_status_completed', array( $WooEvent_Reminder_Email, 'remind_email' ), 10, 1 );
remove_action( 'woocommerce_order_status_completed', array( $WooEvent_Reminder_Email, 'remind_email_fb' ), 11, 1 );
remove_action( 'wooevent_email_reminder', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
remove_action( 'wooevent_email_reminder_2', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
remove_action( 'wooevent_email_reminder_3', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
remove_action( 'wooevent_email_reminder_feedback', array( $WooEvent_Reminder_Email, 'send_mail_fb' ), 10, 1 );
// send email to attendee
remove_action( 'we_send_email_reminder', array( &$WooEvent_Reminder_Email, 'send_mail_attendee' ),10,1 );
return false;
}
return $is_purchasable;
}
With which action/filter, I should use the above or any modifications.
I am able to disabled the event on the basis of category, but already scheduled email are still queued up.
Any suggestions or help will be appreciated.
Thanks

Activating a plugin from inside Woocomerce single product page using a check box

i am looking for a way to activate a plugin from a woocommerce single product page, the plugin displays shipping countdown for delivery but its not relevant to all products and i would like to use a check box inside the single product to turn on and of per product page
the plugin is being activated across all products at the moment using the add action from theme mod to be able to change the position this really is not necessary so if need this could be removed and replaced with some other way on activating the plugin on a per product basis
$scfwc_render_location = get_theme_mod( 'scfwc_render_location');
switch ( $scfwc_render_location ) :
case 'scfwc_after_heading' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 6 );
break;
case 'scfwc_after_price' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 11 );
break;
case 'scfwc_after_short_desc' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 21 );
break;
case 'scfwc_after_add_cart' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 31 );
break;
case 'scfwc_after_single_product_summary' :
add_action( 'woocommerce_product_thumbnails', array( $this, 'scfwc_html_product' ), 30 );
break;
endswitch;
I don't know what class $this is referencing, or how to get an instance of it, so this is pseudo-code. But once you have the meta field displaying and saving in the admin, you can use the meta field's value to conditionally add the scfwc_html_product() method.
function kia_conditionally_add_countdown() {
global $product;
if( $product->get_meta( '_show_countdown', true ) ) {
$my_class = somehow_get_instance_of_class();
add_action( 'woocommerce_single_product_summary', array( $my_class, 'scfwc_html_product' ), 11 );
}
}
add_action( 'woocommerce_before_single_product_summary', 'kia_conditionally_add_countdown' );
This doesn't take into account the theme mod and just hard-codes the priority/position. You could add support for the theme_mod inside the conditional logic, if needed.

Remove an action - Wordpress (Specifically Woocommerce PIP plugin)

I have Woocommerce website with the plugin Print Invoices/Packing Lists installed.
I'm trying to remove an action and I've narrowed down the action to this (shortened) code;
class WC_PIP_Document_Invoice extends WC_PIP_Document {
public function __construct( array $args ) {
parent::__construct( $args );
// add a "View Invoice" link on order processing/complete emails sent to customer
add_action( 'woocommerce_email_order_meta', array( $this, 'order_paid_email_view_invoice_link' ), 40, 3 );
}
}
So I'm looking at removing this using; https://codex.wordpress.org/Function_Reference/remove_action
However as the action as added within a class, I can't quite work out what to pass into the function name. Would it be something like;
remove_action( 'woocommerce_email_order_meta', array( 'WC_PIP_Document_Invoice', 'order_paid_email_view_invoice_link' ), 40 );
Can anyone point me in the right direction?
Many thanks
Try following code that should work for you.
add_action( 'init', 'wpse_106269_remove_hooks', 11 );
function wpse_106269_remove_hooks(){
remove_action( 'woocommerce_email_order_meta', 'action_woocommerce_email_order_meta', 10, 4 );
}

Wordpress remove_action within class

I am trying to remove an action added by the Woocommerce Memberships plugin. Tracing back the actions contains functions it is initially added to the hook under
class WC_Memberships_Frontend {
public function __construct() {
add_action( 'woocommerce_thankyou', array( $this, 'maybe_render_thank_you_content' ), 9 );
But this class is called by a private function and is a protected by the variable that its parent class declaration (as far as I can tell)
class WC_Memberships extends Framework\SV_WC_Plugin {
protected $frontend;
private function frontend_includes() {
// init shortcodes
require_once( $this->get_plugin_path() . '/includes/class-wc-memberships-shortcodes.php' );
\WC_Memberships_Shortcodes::initialize();
// load front end
$this->frontend = $this->load_class( '/includes/frontend/class-wc-memberships-frontend.php', 'WC_Memberships_Frontend' );
}
I have search and tried a number of ways to remove this
remove_action( 'woocommerce_thankyou', array( 'WC_Memberships', 'maybe_render_thank_you_content' ), 9 );
remove_action( 'woocommerce_thankyou', array( 'WC_Memberships_Frontend', 'maybe_render_thank_you_content' ), 9 );
global $WC_Memberships;
remove_action( 'woocommerce_thankyou', array( $WC_Memberships, 'maybe_render_thank_you_content' ), 9 );
global $WC_Memberships_Frontend;
remove_action( 'woocommerce_thankyou', array( $WC_Memberships_Frontend, 'maybe_render_thank_you_content' ), 9 );
None of the above work, and other ways of trying to call WC_Memberships()->frontend; throw errors like 'Cannot access protected property WC_Memberships::$frontend'
Im not sure if the private function or protected variable are getting in the way, or if Im just not understanding something about removing an action within a class or nested classes but help would be greatly appreciated.
Edit:
Based on the code found here Ive tried
remove_action( 'woocommerce_thankyou', array( wc_memberships()->get_frontend_instance(), 'maybe_render_thank_you_content', 9 ) );
but still no success.
My issue was trying to figure out how to match the $this in the original add_action add_action( 'woocommerce_thankyou', array( $this, 'maybe_render_thank_you_content' ), 9 ); to remove it.
I finally stumbled on this chunk of code which showed me how to reference the proper instance of the class.
Final working code:
remove_action( 'woocommerce_thankyou', array( wc_memberships()->get_frontend_instance(), 'maybe_render_thank_you_content', 9 ) );
As you probably know, it's usually not good practice to modify core or plugin files. Using a modification to the answer here , you could try adding to your themes functions.php file
function remove_aggravating_wcactions()
{
remove_action( 'woocommerce_thankyou', 'maybe_render_thank_you_content', 19 );
remove_action( 'woocommerce_thankyou', 'maybe_some_other_content', 20);
...
}
add_action('template_redirect','remove_aggravating_wcactions');

instantiate a class from plugin in WordPress

I have a question about class written in the plugin. Let's say I have this class.
class Woo {
public static init(){
register_activation_hook( __FILE__, array( __CLASS__, 'woo_activate' ));
add_action( 'admin_menu', array(__CLASS__, 'woo_register'));
}
Woo::init();
add_action( 'plugins_loaded', array( 'Woo', 'init' ) );
My question is why put Woo::init(); there where we already have the add_action( 'plugins_loaded', array( 'Woo', 'init' ) );
Are both executed? can woo::init() be deleted and it will work fine? and vice versa?

Resources