Self deactivate plugins after an action occurs

The deactivate_plugins() function is available only after the admin_init action is executed, you will either need to register ‘admin_init’ filter and run the deactivate_plugins() function there or manually include the wp-admin/includes/plugin.php file. I updated your code with the second solution below. class WP_X_Plugin{ public function __construct(){ register_activation_hook( __FILE__, array( $this , ‘activate’ ) ); $url … Read more

Add Product Subtitle to Woocommerce Product Page

This is what I have used to show the product category as a subtitle on my shop archive page add_action( ‘woocommerce_shop_loop_item_title’, ‘woocommerce_shop_loop_item_subtitle’, 20 ); function woocommerce_shop_loop_item_subtitle() { global $post, $product; $categ = $product->get_categories(); echo $categ; } and this is what I used to display it on the single product page add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_single_item_subtitle’, 5 ); … Read more

Handling Body class based on Template

I’m not sure if I understand your question correctly, but… If you want to set body classes based on current page, then you can use this code function my_body_class( $classes ) { if ( is_home() ) { $classes[] = ‘wbody’; } else { $classes[] = ‘gbody’; } return $classes; } add_filter( ‘body_class’, ‘my_body_class’ ); Of … Read more

tracking number field in Woocommerce order [closed]

The syntax to get your custom field is: get_post_meta($post_id, $key, $single); In your context, you should try: $tracking_id = get_post_meta($order->get_order_number(), ‘Tracking_ID’, true); To show you in your example: <?php /* translators: %s: Site title */ $tracking_id = get_post_meta($order->get_order_number(), ‘Tracking_ID’, true); ?> <p><?php printf( esc_html__( ‘Your %s order is completed. Your tracking number is: %s’, ‘woocommerce’ … Read more

Same log message keeps on printing to debug.log file thousand of times

OK, as far as I understand, you’ve put this code: $debug_log = “DEBUG-debug log”; trigger_error($debug_log); //OR error_log($debug_log); directly in your functionsphp` file. It means, that this code will be executed (so new log item will be added to log file) every time the functions.php file is loaded – so during every request to your WP. … Read more

Passing PHP Function Arguments from CLI vs URL

You can do this: function foo_command( $args ) { WP_CLI::success( $args[0] ); } WP_CLI::add_command( ‘foo’, ‘foo_command’ ); And put it in a plugin, then run: wp foo “hello world” And it will print out hello world. Just because the built in subcommands don’t do what you need them to do, doesn’t mean you can’t add … Read more

WordPress 5 WP REST routes – No errors

REST API should always return JSON, so it’s output can be parsed as such. If it’ll return something that is not correct JSON, then your JS scripts may stop working. This is why there should be no errors printed in these requests – such messages break JSON response and make it hard to parse. And … Read more