Is there any way to find which action/hook is fired?
Try this plugin which will show you which actions get fired on a given page.
Try this plugin which will show you which actions get fired on a given page.
$args = array( ‘post_type’ => ‘product’, ‘meta_key’ => ‘YOUR_FIELD_ID’, ‘meta_value’ => array(‘yes’), //’meta_value’ => array(‘yes’), ‘meta_compare’ => ‘IN’ //’meta_compare’ => ‘NOT IN’ ); $products = wc_get_products($args); foreach ($products as $product) { //do your logic }
Try this code to change the default billing country on the checkout page. add_filter( ‘default_checkout_billing_country’, ‘change_default_checkout_country’ ); function change_default_checkout_country() { return ‘US’; // country code } To change default shipping country on the checkout page function change_set_checkout_field_input_value_default($fields) { $fields[‘shipping’][‘shipping_country’][‘default’] = ‘Australia’; return $fields; } add_filter( ‘woocommerce_checkout_fields’, ‘change_set_checkout_field_input_value_default’ );
It’s actually quite simple. Use the woocommerce_product_post_type_link_parent_category_only filter: add_filter( ‘woocommerce_product_post_type_link_parent_category_only’, ‘__return_true’ ); Tried and tested working. PS: The code would go into the theme functions file and __return_true() is a WordPress function.
The action hook publish_post doesn’t work for custom post types. You need to use the following format: publish_{$custom_post_type} As you are using Woocommerce this post type is product so you want to use: publish_product.
You’re damned if you do, and you’re damned if you don’t. But it’s typically better to “do”. I have been working in WordPress support and development for a number of years now – and I can certainly say it’s much better to keep everything up to date. Wait a little bit (2 weeks or so) … Read more
I found what was my problem is priority. Some other plugin was using a 1000 priority, so I had to boost my priority when declaring the hook. That way: add_filter( ‘woocommerce_login_redirect’, ‘share_login_redirect’, 1100, 2 ); instead of add_filter( ‘woocommerce_login_redirect’, ‘share_login_redirect’, 10, 2 );
The order notes are saved as post comments, so you can use the WordPress function get_comments() to get the last note: $args = array( ‘post_id’ => $order_id, ‘orderby’ => ‘comment_ID’, ‘order’ => ‘DESC’, ‘approve’ => ‘approve’, ‘type’ => ‘order_note’, ‘number’ => 1 ); remove_filter( ‘comments_clauses’, array( ‘WC_Comments’, ‘exclude_order_comments’ ), 10, 1 ); $notes = get_comments( … Read more
You can try using template_redirect action hook to check if the current page is product page and after that, you can redirect the user to your shop page. Paste this code into your functions.php add_action(‘template_redirect’,’custom_shop_page_redirect’); function custom_shop_page_redirect(){ if (class_exists(‘WooCommerce’)){ if(is_product()){ wp_redirect(home_url(‘/shop/’)); exit(); } } return; } I have not tested it, but hope it will … Read more
Techno Deviser, probably by mistake, in the foreach loop set value to $fragments[‘div.header-cart-count’] instead append it. Try this modification: function iconic_cart_count_fragments( $fragments ) { foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $fragments[‘div.header-cart-count’] .= ‘<div class=”header-cart-count”>’ .$cart_item_key.'<br><br>’. $cart_item[‘product_id’]. ‘</div>’; } return $fragments; } Or: function iconic_cart_count_fragments( $fragments ) { $cart = WC()->cart->get_cart(); if (!empty($cart)) … Read more