variations

Add sale price programmatically to product variations

荒凉一梦 提交于 2019-12-11 04:28:21
问题 I need to update the sale price programmatically, on variable product and all his variations. What kind of meta field do I need to add? I'm trying to update main product such as: update_post_meta($post_id, '_regular_price', '100'); update_post_meta($post_id, '_price', '50'); update_post_meta($post_id, '_sale_price', '50'); and then I update every single variations update_post_meta($variation_id, '_regular_price', '100'); update_post_meta($variation_id, '_price', '50'); update_post_meta(

Variable product attribute: Customizing each displayed radio buttons text value

℡╲_俬逩灬. 提交于 2019-12-10 14:23:21
问题 In WooCommerce I am using WC Variations Radio Buttons plugin (by 8manos) to replace the typical dropdown selectors with Radio Buttons . I've added the below code to my child themes function.php : // Display the product variation price inside the variations dropdown. add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' ); function display_price_in_variation_option_name( $term ) { global $wpdb, $product; if ( empty( $term ) ) return $term; if ( empty(

Display the default variation price and savings amount on Woocommerce 3

五迷三道 提交于 2019-12-10 11:25:12
问题 I need to display default variation price & with regular price & savings amount on my Woocommerce Homepage & Category Page I found following code on this links answer Display lowest variation price and discounted percentage in WooCommerce add_filter( 'woocommerce_get_price_html', 'custom_price_format', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'custom_price_format', 10, 2 ); function custom_price_format( $price, $product ) { // Main Price $regular_price = $product->is_type(

WooCommerce: Get Product Variation ID from Matching Attributes

会有一股神秘感。 提交于 2019-12-10 11:06:09
问题 How I get product variation id from custom product loop. I have variation attribute like, { 'pa_color'=>'red','pa_size'=>'large'} 回答1: Set of attributes to match are [ 'attribute_pa_color' => 'blue', 'attribute_pa_size' => 'small', ]; Below is the function I ended up creating to achieve this: /** * Find matching product variation * * @param $product_id * @param $attributes * @return int */ function find_matching_product_variation_id($product_id, $attributes) { return (new \WC_Product_Data

WooCommerce Variation Images not displaying

﹥>﹥吖頭↗ 提交于 2019-12-10 09:37:36
问题 On the single product page, when I select a color, the featured image doesn't change. WordPress has been updated to 4.6.1, WooCommerce to 2.6.2, and the Storefront theme to 2.1.2. I have deactivated all plugins except WooCommerce and am using the Storeront theme exactly as I installed it. I cleared all caches, cleared my browser cache (Chrome, latest version),and even went so far as to re-enter all variation images for a single product. Further testing hs yielded the same result. I have no

Update all variations prices of a variable product in Woocommerce

别等时光非礼了梦想. 提交于 2019-12-10 05:03:41
问题 I need to get all variation id and update price in loop. Simple query and loop looks like: $params = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘product_variation’, ‘post_parent’ => $product->get_id() // tried $post-ID ); $variations = get_posts( $params ); foreach ( $variations as $variation ) { $variation_ID = $variation->ID; // tried $post-ID, $product->get_id() $regular_price=34; update_post_meta( $variation_ID, ‘_regular_price’, (float)$regular_price ); update_post_meta( $variation_ID

Get the Product Variation related to default attribute values in WooCommerce

梦想的初衷 提交于 2019-12-08 19:58:55
问题 I would like to display the default product attributes form value and it's regular price in my front end template file. The var_dump below shows options in an array. I Need to get the [default_attributes] values. <?php global $product; echo var_dump( $product ); // Need to get the [default_attributes] values ?> 回答1: To get the default attributes for a variable product you can use WC_Product method get_default_attributes() this way: <?php global $product; if( $product->is_type('variable') ){

Hide variable product dropdown that has a unique variation selected by default in Woocommerce

喜你入骨 提交于 2019-12-08 08:14:54
问题 I have a unique issue. I am using a plugin where they are not able to support the request. I need to split out variations into separate items, but if I copy and paste and turn them into a simple product, then I can't sync the count for the product to track inventory stock. As a workaround I needed to be able to disable the variations I do not need, keeping only the one that I do need. But here is where I am having trouble. If I have one variation enabled, then I do not want to show the

Woocommerce: Display Product Variation Description on order page

你说的曾经没有我的故事 提交于 2019-12-08 06:24:15
问题 I am trying to display the product variation description in the order detail page and in the order email. Following this example Woocommerce: Display Product Variation Description on Cart page it worked perfectly for the cart and also for the checkout. But it seems i can't find the right way of calling it for the order page. This $item = $cart_item['data']; if(!empty($item) && $item->is_type( 'variation' ) ){ echo '<dl><dd>' . $item->get_variation_description() } is not working, as it calls

PHP - preg_match - How to match a string upper/lower case with anything before or after it?

丶灬走出姿态 提交于 2019-12-07 15:08:21
问题 I have a part of a function that goes like this: if (preg_match("#\bscript\b#",$userInput)) { $bannedWord = 'script'; logHax(); return TRUE; } This is causing a problem for what I am trying to accomplish because it will only match the exact word "script" and not variations of it, like "ScriPt" or " <script> ". What I would like to have is the examples of the not matched strings along with the original string return true. Could someone provide me with a bit of understanding on this matter.