product

WooCommerce single product custom Tab displaying a page content

ⅰ亾dé卋堺 提交于 2019-12-24 10:58:38
问题 I have created a custom tab for a single product and would like to know with the code below if there is a way to specify a certain page to act as the content for that tab? add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' ); function woo_new_product_tab( $tabs ) { // Adds the new tab $tabs['test_tab'] = array( 'title' => __( 'Seller Disclosure', 'woocommerce' ), 'priority' => 50, 'callback' => 'woo_new_product_tab_content' ); return $tabs; } function woo_new_product_tab_content()

Exclude downloadable products from shop pages in Woocommerce

时光毁灭记忆、已成空白 提交于 2019-12-24 10:38:46
问题 I'm developing a Woocommerce shop with both physical and downloadable products. I would like to alter the standard query for the loop to exclude all downloadable products, but I can't figure out a way to do it. I would like these products to only be displayed on a certain archive page, which is no problem to achieve. I'm doing a few other alterations of the query using pre_get_post, but I can't seem to find an option for downloadable products. All my products are simple products. Any help

Enable Ajax add to cart button on products custom loop in Woocommerce

99封情书 提交于 2019-12-24 10:37:31
问题 This is the code which I have written for the custom loop code for the product-archive page. I want to use ajax for adding products to the cart. How should I do it? I would also like to know which woocommerce function show woocommerce notices to the customer. Like when I click add to cart Notice should be shown to the client that product has been added. $args = array( 'post_type' => 'product', 'posts_per_page' => 12, ); $loop = new WP_Query($args); if ($loop->have_posts()) { while ($loop-

Hide all on sale products on Woocommerce shop page

有些话、适合烂在心里 提交于 2019-12-24 10:28:26
问题 Would it be possible to hide all the products marked as "sale" on the standard WooCommerce shop page? The sale products will be posted on a separate Sale page. 回答1: To hide all on sale products (except variable products) on Woocommerce shop page, use: add_filter( 'woocommerce_product_query_meta_query', 'on_sale_products_not_in_archives', 10, 2 ); function on_sale_products_not_in_archives( $meta_query, $query ) { // For woocommerce shop pages if( is_shop() ){ $meta_query[] = array( 'key' => '

Add product quantity field limited to the available quantity in Woocommerce shop loop

隐身守侯 提交于 2019-12-24 10:22:43
问题 In Woocommerce, I'm using this code to add the quantity field in woocommerce shop loop: /** * Override loop template and show quantities next to add to cart buttons */ add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 ); function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) { if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold

Change product status if prices are updated in Woocommerce 3

空扰寡人 提交于 2019-12-24 10:17:46
问题 I need to change product post_status in a hook. I trying to make product get back to "pending" status everytime vendor change the price. add_action( 'updated_post_meta', 'mp_sync_on_product_save', 10, 4 ); function mp_sync_on_product_save( $meta_id, $post_id, $meta_key, $meta_value ) { if ( $meta_key == '_price' ) { // edited price if ( get_post_type( $post_id ) == 'product' ) { $product = wc_get_product( $post_id ); $product['post_status'] = 'pending'; //how to update this? // var_dump(

WooCommerce Show Product Total Sales after Custom a Date in Frontend

故事扮演 提交于 2019-12-24 09:26:20
问题 I want to show product total sales after custom date: I have this code, but I would like to custom it for showing only the total sales after a custom date for example 05/26/2016 function total_sales() { global $product; $units_sold = get_post_meta(206, 'total_sales', true); echo '<p>' . sprintf(__('Units Sold: %s', 'woocommerce'), $units_sold) . '</p>'; } 回答1: total_sales holds the total sales count of all time, So you need to write custom query to get sold count between specific date. /

Add dropdown to products and display the value on Woocommerce cart

只愿长相守 提交于 2019-12-24 08:19:51
问题 I'm having trouble adding a custom dropdown to the cart meta and displaying it in the cart. The code below works for a number field that is also on the single product page, but not for the dropdown for some reason. Does anyone know why? The code is as follows: // Dropdowns-in-ends starts here add_action( 'woocommerce_before_add_to_cart_button', 'func_dropdown_in_ends'); function func_dropdown_in_ends() { printf( '<div class="class_dropdown_ends"><label for="id_dropdown_one_end">I andre enden

Show only featured products in Woocommerce shop page

北慕城南 提交于 2019-12-24 07:58:32
问题 I want to display in default shop page from WooCommerce only featured products, nothing more... It's there a solution to display in WooCommerce shop template only the featured products? 回答1: You should use this custom function hooked in woocommerce_product_query_tax_query filter hook, that will display only featured product in shop (but not in other archives pages): // Display featured products in shop pages add_filter( 'woocommerce_product_query_tax_query', 'custom_product_query_tax_query',

WooCommerce - Conditional has_term doesn't work anymore after updating

情到浓时终转凉″ 提交于 2019-12-24 07:17:19
问题 So I'm using the conditional of tho code Snippet from this example, with this thread code with success: BUT It's no longer working after updating my WordPress Core and WooCommerce Plugin. if ( is_product() && has_term( 'sample-category', 'product_cat' ) ){ add_action( 'woocommerce_after_add_to_cart_button', 'add_custom_button', 10, 0 ); function add_custom_button() { global $products; $product_link = get_permalink( $products->id ); $sample_link = substr($product_link, 0, -1) . '-swatch-card/'