New answers tagged

0

The answers given above aren't wrong, but they both lean on jQuery. That is not a good idea because jQuery is slowly being escorted out of the building by the powers that be at Automattic. More importantly, when you actually look at the FacetWP documentation on How to Use FacetWP Hooks, the instructions clearly tell you to put the code somewhere else. ...


0

For retrieving 10 Most Sold Products in WooCommerce we are using wp_query manipulation with meta_key as “total_sales” and orderby “meta_value_num”. In short we are displaying products as per the total sales number. Here is the code for this. $args = array( 'post_type' => 'product', 'meta_key' => 'total_sales', 'orderby' => '...


0

When I am using a php script in my Wordpress installation, I have special functions in the child theme, in functions.php So I have to require that as well. Also you want to make sure that SHORTINIT is not defined as TRUE, or else you lose many Wordpress functions. Here is how I do it. ignore_user_abort(true); $path = $_SERVER['DOCUMENT_ROOT']; require( $...


1

You can try something like this: add_action( 'woocommerce_before_add_to_cart_form', 'add_list_completed_orders' ); function add_list_completed_orders() { // get orders $orders = wc_get_orders ( array ( 'status' => array( 'wc-completed' ), 'type' => 'shop_order', 'limit' => -...


0

You could setup a redirect at the top of the archive page template for users that don't match your criteria, something like: $user = wp_get_current_user(); $allowed = array( 'editor', 'administrator' ); $redirect_url = 'https://url-to-redirect-to'; if ( ! $user || ! array_intersect( $allowed, $user->roles ) ) { wp_safe_redirect( $redirect_url, 401 ); ...


0

You can use this woocommerce filter: //Hide Shippping and Billing form users backend add_filter( 'woocommerce_customer_meta_fields', 'hide_shipping_billing' ); function hide_shipping_billing( $show_fields ) { unset( $show_fields['shipping'] ); unset( $show_fields['billing'] ); return $show_fields; }


0

Solved Problem with activated the prevent "remove <br> and <p> tag" option and inserted a <p><!-- Break --></p> when using a <p> tag. The comment prevent that the tag would remove or filled with &npsb


0

I got this solution from https://stackoverflow.com/a/57218305/900557 Add this to your theme's functions.php The Answer from Chandrakant Devani helped, but broke other searches in the admin. Adding an if seems to avoid breakages if ( is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product') full code: ...


1

The main problems with what you've got are tha your close bracket } for the is_product() case is in the wrong place: it should be before the elseif not at the bottom of the block. (This is what Tom meant by indenting your code correctly: if you'd indented each {...}, which your IDE will do for you, this would have been obvious.) this code, defining the ...


0

I've managed to write an SQL query that would get all product variation IDs that do not have both size and color set up (not present in the wp_postmeta table). After that I just need to loop through these IDs and delete those variations using wp_delete_post. This is the query: SELECT p.ID FROM wp_posts p LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id ...


2

hook into the woocommerce hook is_purchasable add_filter("woocommerce_is_purchasable", function($product, $isPurchasable) { if(!$isPurchasable) return $isPurchasable; $productId = $product->get_id(); $user = wp_get_current_user(); if($user->exists() && $productId == 769) { $userId = $user-&...


0

Here is the code: function ur_update_role( $valid_form_data, $form_id, $user_id ) { global $table_prefix; $assign_roles_list = array(); if( isset( $valid_form_data['billing_ie']) && !empty( $valid_form_data['billing_ie']->value ) ) { array_push( $assign_roles_list, 'ie' ); } if ( ! empty( $assign_roles_list ) ) { // Re-ordering roles according to ...


0

It sounds like a bug in the plugin. If you have set rounding to 2 decimals in your Woocommerce -> General Settings then I suspect that the plugin is not using this field for rounding purposes. If their tech support is not acknowledging this as their problem maybe you could investigate the plugin's php files for yourself and see if you can spot the field ...


2

I had an issue on latest WordPress 5.6 and Woocommerce 4.8. The call in the line below is deprecated. $fields = $checkout->get_checkout_fields(); This is by now a working version. But the $_POST access is not the best solution. A more clean way would be to access the password_confirm value from the $posted variable in the last function ...


0

I won't go in code details, but I would consider two different strategies among many others: using a custom query using WPDB class, based on WooCommerce queries; unhook all undesired filters and actions from WordPress, WooCommerce and other plugins. I would probably start with the second one.


0

//this is how i added AND filter on product tags function product_tag_and_filter( $query ) { if ( is_admin() || ! $query->is_main_query() ){ return; } if(is_product_category()){ $tax_query = array(); // add meta_query elements if( !empty( get_query_var( 'product_tag' ) ) ){ ...


0

Please note if you trying to override woocommerce shop page such way as suggested above To override the shop page, copy: wp-content/plugins/woocommerce/templates/archive-product.php to wp-content/themes/your_theme_name/woocommerce/archive-product.php You also have impact on category shop pages. If you want have only impact on shop page separately it will ...


0

Steven is correct, but new WooCommerce styles apply styles to that form differently now so the style code should be .woocommerce form.checkout_coupon { display:block !important; }


0

You miss the required remove_action() parameter — the name of the function to remove. See the Code Reference. <?php add_action( 'woocommerce_login_form', 'woocom_extra_register_fields' ); function woocom_extra_register_fields () { if ( is_page( 'installation' ) ) { remove_action( 'woocommerce_login_form', 'woocom_extra_register_fields', 10 );...


0

If you are on a term archive, such as a tag page, or a category page, you can retrieve that term like this: $term = get_queried_object(); And show the count like this: $count = $term->count; Keep in mind however that: Custom queries will override this and interfere. get_queried_object always uses the main query get_queried_object will only return a ...


0

Put this Code On Your Header and Check It is a working On Your header <?php if (is_tax('product_cat')) { $category = get_queried_object(); $get_id = $category->term_id; echo do_shortcode('[products_counter category="'.$get_id.'" ]'); } ?> functions.php ...


0

Try the code below in functions.php: function wc_show_sku_grouped_product($value, $grouped_product_child){ global $product; $sku = $product->get_sku(); if(!empty($sku)){ $value .= "<div><strong>".__( 'SKU:', 'woocommerce' )." ".$sku."</strong></div>"; } return $value; } add_filter('...


0

Rather than adding shortcode you have to add the hook which is on the product category page: // Use this hook for working directly on category page // add_action( 'woocommerce_archive_description', 'show_category_product_counts', 10 ); // Use this shortcode hook if you want to put on anywhere in the category page if you are using Elementor/WPBakery ...


1

Following below code according your need To get the selected variation attributes using get_variation_attributes( ) method. // Get an instance of the WC_Order object from an Order ID $order = wc_get_order( $order_id ); // Loop though order "line items" foreach( $order->get_items() as $item_id => $item ){ $product_id = $item->...


0

When registering the taxonomy just set public to false, and it' won't be accessible on the front end. Just make sure to specify show_ui to true, otherwise it will use the public value and be hidden. register_taxonomy( 'my_taxonomy', 'product', [ 'public' => false, 'show_ui' => true, ] ); If you're registering the ...


0

Check this one: How to add a new endpoint in woocommerce Update In your callback function include your extended template page because output is expected. ex: function foren_content() { include('woocommerce/myaccount/custom-page.php'); } Then inside custom-page.php call the desired content with get_post(ID) or if you have your endpoint registerd in ...


1

It sounds like you want to add an item to the cart of a specific user, not just the session of the browser making the request. WooCommerce's add_to_cart function will only add an item to the cart of the user making the request. I don't believe WooCommerce has an easy one-line solution, but you could make your own function. There's a pretty good example in ...


0

Initially. It should be said that WooCommerce is considered a plugin and therefore your question could probably be flagged as 'Off-topic'. This (however) is such a bullshit and self-deprecating for this StackExchange, so I'll answer it anyway. :-) But next time you have a WooCommerce-question, you should ask it on StackOverflow (apparantly). My first ...


Top 50 recent answers are included