Forum Replies Created

Viewing 15 replies - 1 through 15 (of 39 total)
  • Ok thanks I will test resave permalink. ??

    Any news on that? Is this plugin still active?

    Same problem here, when I’m in English (not the default langage of the website), clic on add to favorite add the product to the favorite but after if I clic on the “See my favorites” in the popup, the link is not good: “/en/favorites/55B8B2/”, it adds “55B8B2” at the end.
    I do not use any cache plugin.

    Thread Starter dantahoua

    (@dantahoua)

    Perfect! I will ! Thanks! ??

    Thread Starter dantahoua

    (@dantahoua)

    Ok thanks that sounds great! ??

    Thread Starter dantahoua

    (@dantahoua)

    From what I understand I can choose another field for quantity, so I could do this:
    -Show Group of fields 2 if quantity field is equal or superior to 2.
    -Show Group of fields 3 if quantity field is equal or superior to 3.
    Or is there only “equal” / “not equal” (I need superior)…

    Thread Starter dantahoua

    (@dantahoua)

    Thanks! It’s working great! ??

    Still not fixed!!! My error_log start to be very fat… Do this plugin still maintained?

    Thread Starter dantahoua

    (@dantahoua)

    Here is the updated code:

    function sync_variations_stock($order_id)
        {
            if (is_admin()) return; // make sure it's a user order and we aren't on admin dashboard
            $order = wc_get_order( $order_id );
            foreach( $order->get_items() as $item ) {
                if ($item->get_type() !== 'line_item') continue;    //if $item is not a product or variation
                $order_variation_count   = $item->get_quantity();
                $order_product_id        = $item->get_product_id();
                $order_variation_id      = $item->get_variation_id();
    
                if ( ! $order_variation_id ) continue;    // if the item isn't a variation
    
                $order_variation         = wc_get_product($order_variation_id);
                $order_variation_attribs = $order_variation->get_variation_attributes();
                if ( isset($order_variation_attribs['attribute_pa_dates']) ) {
                    $current_date_attrib = $order_variation_attribs['attribute_pa_dates'];
    //Get the stock of the current variation for updating others.
                    $new_stock = $order_variation->get_stock_quantity();
                } else {
                    continue; // stop if the variation in the order doesn't have 'pa_dates' attrib
                }
    
                $product    = wc_get_product( $order_product_id );
                $variations = $product->get_available_variations();
                foreach ( $variations as $variation ) {
                    if ( $variation['variation_id'] == $order_variation_id ) {
                        continue;   //if this variation is the one we have in our order
                    }
                    if ( ! isset( $variation['attributes']['attribute_pa_admissible-emploi-quebec'] ) || !isset( $variation['attributes']['attribute_pa_dates'] ) ) {
                        continue;   //if this variation does not have the color or date attrib
                    }
    
                    if ( $variation['attributes']['attribute_pa_dates'] == $current_date_attrib ) {
    
                        /*
                         * wc_update_product_stock function sets the stock quantity if the variation stock management is enabled
                         * NOTE: This function may cause a negative stock even if the variation backorder is set to false
                         */
                        //wc_update_product_stock( $variation['variation_id'], $order_variation_count, 'decrease' );
    //Update stock of other variation with the stock number of the one just bought
                        wc_update_product_stock( $variation['variation_id'], $new_stock, 'set' );
                        wc_delete_product_transients($variation['variation_id']); // Clear/refresh the variation cache (optionally if needed)
                    }
                }
            }
        }

    And here is the code on StackOverflow
    And thanks again, Internet is a better place with peoples like you!

    Thread Starter dantahoua

    (@dantahoua)

    @yashar, I already checked all plugin for this… Sadly all plugin just add or subtract an amount (or a %) from the price of the product and it’s always the same amount for all product. In my case, the price variation is different from product to product… So the custom way was the only solution there… ??

    Thread Starter dantahoua

    (@dantahoua)

    Someone kindly help me also on StackOverflow. Here is the code which work as Woocommerce do not allow to make “cross variation” stock/price management…
    If it could help someone else! ??

    add_action('woocommerce_thankyou', 'sync_variations_stock');
    //woocommerce_thankyou
    //woocommerce_order_status_changed
    //woocommerce_payment_complete
    //woocommerce_order_status_processing
    //woocommerce_order_status_completed
    
    function sync_variations_stock($order_id)
    {
        $order = wc_get_order( $order_id );
        foreach( $order->get_items() as $item ){
            $product_id = $item->get_product_id();
            $product_variation_id = $item->get_variation_id();
    
            if (!$product_variation_id) return; // if the item isn't a variation
    
            $date_variation = get_post_meta( $product_variation_id, 'attribute_pa_dates', true);
            $sponsored_variation = get_post_meta( $product_variation_id, 'attribute_pa_admissible-emploi-quebec', true);
            $new_stock = (int) get_post_meta( $product_variation_id, '_stock', true);
            
            if ( ! $date_variation && ! $sponsored_variation ) return;  //if the variation doesn't have date and color attributes
    
            $args = array(
                'post_parent' => $product_id,
                'post_type' => 'product_variation',
                'posts_per_page' => -1,
                'meta_query' => array(
                    array(
                        'key' => 'attribute_pa_dates',
                        'value' => $date_variation,
                        'compare' => '='
                    ),
                    array(
                        'key' => 'attribute_pa_admissible-emploi-quebec',
                        'value' => $sponsored_variation,
                        'compare' => '!='
                    )
                ),
            );
            $other_date_variations = get_posts($args);
    
            if( is_array($other_date_variations) && !empty($other_date_variations) ){
                foreach ($other_date_variations as $date_variation) {
    
                    // do your stock updating proccess here. (updateStockVariation() as you write in your code)
    
                    $variation_id = $date_variation->ID;
                    $date_variation_stock = (int) get_post_meta( $variation_id, '_stock', true);
                    if ($date_variation_stock > 0) {    //to prevent backorders
                        //$date_variation_stock =  $date_variation_stock - 1;
                        $date_variation_stock = $new_stock;
                        update_post_meta($variation_id, '_stock', $date_variation_stock);
    
                        // if the variation is now out-of-stock, set it as so
                        if ($date_variation_stock === 0) {
                            update_post_meta($variation_id, '_stock_status', 'outofstock');
                            wp_set_post_terms( $variation_id, 'outofstock', 'product_visibility', true );
                        }
                    }
                }
            }
        }
    }
    • This reply was modified 5 years, 8 months ago by dantahoua.
    Thread Starter dantahoua

    (@dantahoua)

    Thanks Felipe. I did this, put the variations on “any”, set up stock for “dates”, price for “sponsored”… I even tested one think, I set up the stock on “0” for one of the two “dates”, but I’m still able to order it!
    When I order something in stock, the stock do not decrease after ordering.
    I made those test:
    -Create a “simple” product and order it. Stock is decreasing as expected.
    -Removing my theme and using the default theme with my “variable product. Stock is not decreasing for the variation I ordered…

    Note that the “dates” attribute is created per product as it change from product to product. The “sponsored” attribute is created in Products->Attributes as it the same two option for all my lessons…

    Edit: Finally I saw that attribute created per product are also created in Product->Attributes…

    I didn’t check the manage stock at product level for the variable product as we want it to be managed per “dates” variation…

    Weird, should work, still not working… Are you sure woocommerce is able to mange Stock this way?

    Second edit: I made a test with a product with just “dates” variation. And it works as it should (stock decrease, even show in the product page). It’s when I made “cross” variations that is it not working…

    • This reply was modified 5 years, 8 months ago by dantahoua.
    • This reply was modified 5 years, 8 months ago by dantahoua.
    Thread Starter dantahoua

    (@dantahoua)

    Ok thanks. I did this but it’s weird, stock do not decrease in Date when buying… I buy a sponsored for the 10th of June for exemple, but the “10th of june” stock do not decrease after… I have no hook or other think that would interfere for now…

    Thread Starter dantahoua

    (@dantahoua)

    I answer to my last question, seems everything is in Post_Meta so you could retrieve them by get_post_meta($post->ID).

    Thread Starter dantahoua

    (@dantahoua)

    Ok, when using a query_post(), how can I get the “start-date” or the “end-date” of the event as the object returned by wordpress is a standard post object, so missing the “event” variable…

Viewing 15 replies - 1 through 15 (of 39 total)