Hot answers tagged

7

An attachment is a Post The posts table contains information on the attachment post. In WordPress every uploaded media has it's own post entry, where post_type is 'attachment' and post_status is 'inherit'. In fact, you can get attachment post types using functions used to get other post types, like post, page or any CPT. That includes WP_Query, ...


4

I know this post is old, but to keep this question updated: As of WooCommerce 2.4.4 woocommerce_process_product_meta_variable no longer works, and it must be changed to woocommerce_save_product_variation So, Change: add_action( 'woocommerce_process_product_meta_variable', 'save_variable_fields', 10, 1 ); Into: add_action( ...


4

There are approx. 10,000 items returned by the query. That's your problem right there. No matter what you do inside the loop, WordPress is still loading 10,000 post objects into memory. Batch it up and sprinkle a little magic in your query arguments: $args = array( 'fields' => 'ids', // MAGIC! Just get an array of id's, no objects ...


4

Okay, based on answers on link above (where I got the old code and there are people that help to answered), I put the modification code for my website. I tried it and it's working like charm. Change: add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 2 ); Into : add_action( 'woocommerce_variation_options', ...


4

The problem with your approach is that woocommerces product category is a custom taxonomy called product_cat. But with cat you are addressing the built-in category. Taxonomies can be addressed with a tax query, simplified example below: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && ...


3

Your code is deprecated in latest version. You should use this code to get the width: $size = wc_get_image_size( 'shop_catalog' ); $placeholder_width = $size['width'];


3

Looking further into the WooCommerce source, they fortunately, provide a filter named woocommerce_product_data_tabs which will allow you to conditional unset tabs. I've provided an example below: add_filter('woocommerce_product_data_tabs', function($tabs) { /** * The available tab array keys are: * * general * inventory * ...


3

There is almost never a scenario where executing PHP code entered from the wysiwyg editor is a good idea. It opens up a whole bunch of security issues. The best way to achieve what you are looking for is to setup a custom short code that will return the link you are interested in. Add something like this to your functions.php file in your theme. ...


3

I solve This To get the current category ID. $cate = get_queried_object(); $cateID = $cate->term_id; echo $cateID; and it works like a charm.


2

As explained in their documentation WooCommerce provides a templating structure. Copying WC in your theme won't get you anywhere. Create a woocommerce folder in your theme. Copy any template inside the templates folder of WC inside your woocommerce theme folder. Beware you need to keep the structure from templates folder intact in your woocommerce theme ...


2

Change your args to be like this: $meta_query = WC()->query->get_meta_query(); $meta_query[] = array( 'key' => '_featured', 'value' => 'yes' ); $args = array( 'post_type' => 'product', 'stock' => 1, 'showposts' => 6, 'orderby' => 'date', 'order' => 'DESC', 'meta_query' ...


2

Unfortunately, it's not possible with all plugins. This is a feature the developer has to provide on their own. Usually how it works is the plugin will look for the template file in the child theme first. If it's not found there, it looks for the template in the parent theme. Finally, if it's not found in either of those places, it uses the template ...


2

remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10,0); remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20,0); remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10,0); I hope it works for you =)


2

This is because you're doing it too early. You need to wrap your code in the necessary hook so that it occurs at the correct time. Because you don't tell get_field the ID of the current post, it needs to know which post to get the field from, and it does this by referencing the global variable $post, which gets set when you call the_post, or by WP Core ...


2

If you look at woocommerce/templates/content-single-product.php you'll see that the product summary is constructed using hooks with different priorities. Here's the relevant section: <?php /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title - 5 * @hooked ...


2

You have a typo in $_SESSION['odertype'], should be $_SESSION['ordertype']. You are also ASSIGNING a value instead of testing it for equivalency, try ==. If in doubt you can always use var_dump($_SESSION) to get all the values stored there.


2

Following @Burgi's answer, the correct snippet should be: function jk_woocommerce_quantity_input_args( $args, $product ) { if ( isset( $_SESSION['ordertype'] ) && // Never assume an array index exists $_SESSION['ordertype'] == 'local_delivery' && // Note == "same as" operator, not = "assign" ...


2

You can hook into woocommerce_variable_price_html and reformat the price to include or. This will replace the &ndash; with or on all products with multiple differing prices. add_filter('woocommerce_variable_price_html', 'custom_variation_price_seperator', 10, 2); function custom_variation_price_seperator( $price, $product ) { $price = ''; ...


2

I would add it from the start so you don't have to go back to it, and it's a really simple process of creating a woocommerce.php file in your theme and then add the following to your functions.php add_action( 'after_setup_theme', 'woocommerce_support' ); function woocommerce_support() { add_theme_support( 'woocommerce' ); } To create the ...


2

You're close - just need to tweak your arguments: <?php echo get_user_meta( $customer_id, 'billing_phone', true ) ?> Just make sure $customer_id is the ID of the user - you probably want get_current_user_id() instead.


2

Just round the decimal to two digit as per your requirement. $myID = 2859; $myorder = new WC_Order($myID); foreach ($myorder->get_items('line_item') as $item) { $rounded_total = round($item["line_total"],2);// allow 2 decimal and avoid further $Data = $Data.OrderLine($item["name"], $rounded_total, $item["line_tax"], $item["qty"], ...


2

I'm not familiar with Woocommerce, but in short, get_template_part() only look for template parts in parent and child themes, not in plugins. If you look at the source code, get_template_part() uses locate_template which have the following source code (which is where the actual template part is searched for) function locate_template($template_names, $load ...


2

As you may or may not know any post meta data is stored in a new table, $wpdb->postmeta. This table has four fields: 'meta_id' - A unique id for each entry. 'post_id' - The ID of the post for this metadata. 'meta_key' - The name of the 'key'. 'meta_value' - The value associated with the key. To use metadata in your theme use the get_post_meta() ...


2

1) There is a hook for the first one: You can use the apply_filters Their code: apply_filters( 'woocommerce_get_discounted_price', $price, $values, $this ); Your code: add_filter( 'woocommerce_get_discounted_price', function($price, $values, $this) { //return whatever you want },10,3 ); //*PHP 5.3 and up you can pass whatever function you want ...


2

If I understand you, what you are doing is wildly complicated. All you should need is a simple pre_get_posts filter: add_filter( 'pre_get_posts', 'modified_pre_get_posts' ); function modified_pre_get_posts( $query ) { if ( $query->is_search() ) { $query->set( 'post_type', 'product' ); } return $query; } Plus your filter that adds ...


2

I had used this plugin for similar scenario. Please check it's BOGO (Buy One Get One) feature. That will address your requirement.


2

Please go through the code below. I have tried and tested :) /** * Adds a box to the side column on the Order edit screens. * It checks if the order status is completed & then adds meta box. */ function add_drivers_meta_box() { global $current_screen; /* In the second condistion below, please change it to correct string for 'shipped' ...


2

Fixed query select p.ID as order_id, p.post_date, i.order_item_name, max( CASE WHEN im.meta_key = '_product_id' and i.order_item_id = im.order_item_id THEN im.meta_value END ) as Prod_ID from wp_posts as p, wp_postmeta as pm, wp_woocommerce_order_items as i, wp_woocommerce_order_itemmeta ...


2

Many thanks to Nathan Powell for the fix. Changing get_stylesheet_directory() to get_stylesheet_directory_uri() will return the correct URL. get_stylesheet_directory() returns the absolute server path to child or parent theme (hence my previous issue) whereas get_stylesheet_directory_uri() returns the properly formed URI of child or parent theme. I ...


2

The code you have provided is incomplete. Not sure if that is the only code you are using to achieve what you want. So, besides first code block which you have provided, bellow I am adding all rest of the code which is required to show the new field on backend in 'Order Details' box and make it editable through custom fields. Please note, in your second code ...



Only top voted, non community-wiki answers of a minimum length are eligible