Shortcode and get_template_part

Function get_template_part() load file only from theme directory (or child theme). There is no filter or action hook that would change this behavior. You will need to write your own get_template_part() variant to load files from the plugin directory (replace the locate_template() call from the original function). Or write an explicit: $query->the_post(); include plugin_dir_path( __FILE__ … Read more

Checkbox field that add a subscription product and change prices of other products in checkout and cart page

I solved the my issue. this code may help others in future. // Display a custom checkout field add_action( ‘woocommerce_checkout_before_terms_and_conditions’, ‘custom_checkbox_checkout_field’ ); function custom_checkbox_checkout_field() { $value = WC()->session->get(‘add_a_product’); woocommerce_form_field( ‘cb_add_product’, array( ‘type’ => ‘checkbox’, ‘label’ => ‘  ’ . __(‘Please check here to get VIP Membership’), ‘class’ => array(‘form-row-wide’), ), $value == ‘yes’ ? true : … Read more

Is there an option to execute javascript file only on plugin activation

Here is the solution: register_activation_hook( __FILE__, ‘rest_api_hook’ ); /** * Runs only when the plugin is activated. */ function rest_api_hook() { /* Create data */ set_transient( ‘rest_api’, true, 5 ); } /* Add notice */ add_action( ‘admin_notices’, ‘rest_api_hook_exec’ ); /** * Rest API Notice on Activation. */ function rest_api_hook_exec() { /* Check transient, if is … Read more

AJAX update fails for public/non-admin users

Alright, I came across another answer that’s finally solved this. I had a function (in functions.php) which revoked admin access to some user types I’d created with custom privileges – that was blocking non-admin access to admin-ajax.php. Old/new function below: Old function // Revoke dashboard access add_action(‘admin_init’, ‘restrict_access_admin_panel’); function restrict_access_admin_panel(){ global $current_user; get_currentuserinfo(); if ($current_user->user_level … Read more