Tom Anbinder

Forum Replies Created

Viewing 15 posts - 31 through 45 (of 1,178 total)
  • Author
    Posts
  • in reply to: Need Variation SKU to be Product EAN + variation ID #127575
    Tom Anbinder
    Moderator
    Plugin Support

    Hi, Nanette,

    I believe we can solve your task with this PHP snippet:

    add_filter( 'woocommerce_product_variation_get_sku', function ( $sku, $variation ) {
        $parent = wc_get_product( $variation->get_parent_id() );
        return $parent->get_meta( '_alg_ean' ) . '_' . $variation->get_id();
    }, 10, 2 );

    Please give it a try and let me know what you think.

    in reply to: breaks in e-mail #127221
    Tom Anbinder
    Moderator
    Plugin Support

    Hi,

    I’ve just tested it on my server, but unfortunately, I couldn’t reproduce the issue – line breaks are added to the email here. Could you please check if your “Email type” option is set to “HTML” (in “WooCommerce > Settings > Emails > Custom email #X > Email Data > Email type”)? And what about other HTML tags, for example, <p></p> – is it ignored as well?

    in reply to: Date Formats #126529
    Tom Anbinder
    Moderator
    Plugin Support

    Hi, Chris,

    The link on the settings page under the Date(s) field doesn’t work.

    Thank you for pointing it out – will fix it in the next plugin version.

    We would like to run a sale from 12:00 am on October 31 to 11:59 pm on November 3rd and are looking for the correct format.

    I think what you need is:

    October 31 00:00:00 - November 3 23:59:59

    Can you please post the accepted date and time formats here?

    The “Date(s)” option must be set as date range(s) in from - to format, i.e., dates must be separated by the hyphen - symbol, e.g.:

    14.02.2021 15:00 - 26.02.2021 15:00

    You can add multiple date ranges separated by the semicolon ; symbol, i.e., from1 - to1; from2 - to2; .... The algorithm stops on the first matching date range.

    Dates can be set in any format parsed by the PHP strtotime() function. However, don’t use the hyphen - symbol – it’s reserved for separating from and to values.

    Examples

    Enable discount on the exact dates:

    14.02.2021 15:00 - 26.02.2021 15:00

    Enable discount only before 3:00 PM each day:

    00:00:00 - 14:59:59

    Enable discount only before 3:00 PM each day, or before 5:00 PM on Mondays:

    00:00:00 - 14:59:59; Monday 00:00:00 - Monday 16:59:59

    Enable discount for the summer months only:

    first day of June - last day of August 23:59:59

    Enable discount for February only:

    first day of February - last day of February 23:59:59
    in reply to: EAN not visible in Product Catalog Pro #125169
    Tom Anbinder
    Moderator
    Plugin Support

    Update: I’ve mixed up the “Product Catalog Feed Pro” plugin with the “Product Feed PRO” plugin, sorry about that.

    For the “Product Catalog Feed Pro” plugin – it looks like this plugin doesn’t “like” the leading underscore symbol in our field’s name, i.e., _alg_ean. So you must set it to something without an underscore, e.g., alg_ean. This can be done in “WooCommerce > Settings > EAN > Advanced > Meta key”. Then you should be able to select it in the “Product Catalog Feed Pro” plugin settings:

    Product Catalog Feed Pro - EAN field mapping

    P.S. If you’ve already entered EANs for your products, they will disappear after you change the meta key to alg_ean. To bring them back, you can use our “Copy from product meta” tool in “WooCommerce > Settings > EAN > Tools” – set the “Meta key” option to _alg_ean there and run the tool.

    P.P.S. The “Product Catalog Feed Pro” plugin gets its custom fields list automatically by extracting meta keys from your products, so you need to set EAN for at least one of your products for the field to show up in their list. Also, the “Product Catalog Feed Pro” plugin saves the custom fields list in a transient with 24 hour expiration, which means that you need to either wait or delete the transient with this PHP code:

    delete_transient( 'products_meta_keys' );
    in reply to: EAN not visible in Product Catalog Pro #125160
    Tom Anbinder
    Moderator
    Plugin Support

    Hi,

    You need to select the “alg ean (Custom attribute)” value when mapping the field in the “Product Feed PRO” plugin:

    Product Feed Pro - EAN field mapping

    in reply to: Change Stock By Product Tag #124788
    Tom Anbinder
    Moderator
    Plugin Support

    Hi, Julian,

    Haven’t we solved it with you with this snippet?

    /**
     * alg_wc_stock_triggers_function_increase.
     */
    add_filter( 'alg_wc_stock_triggers_function_increase', function () {
        return 'my_wc_maybe_increase_stock_levels';
    } );
    
    /**
     * my_wc_maybe_increase_stock_levels.
     *
     * @see https://github.com/woocommerce/woocommerce/blob/7.7.0/plugins/woocommerce/includes/wc-stock-functions.php#L123
     */
    if ( ! function_exists( 'my_wc_maybe_increase_stock_levels' ) ) {
        function my_wc_maybe_increase_stock_levels( $order_id ) {
            $order = wc_get_order( $order_id );
    
            if ( ! $order ) {
                return;
            }
    
            $stock_reduced    = $order->get_data_store()->get_stock_reduced( $order_id );
            $trigger_increase = (bool) $stock_reduced;
    
            // Only continue if we're increasing stock.
            if ( ! $trigger_increase ) {
                return;
            }
    
            my_wc_increase_stock_levels( $order );
    
            // Ensure stock is not marked as "reduced" anymore.
            $order->get_data_store()->set_stock_reduced( $order_id, false );
        }
    }
    
    /**
     * my_wc_increase_stock_levels.
     *
     * @see https://github.com/woocommerce/woocommerce/blob/7.7.0/plugins/woocommerce/includes/wc-stock-functions.php#L268
     */
    if ( ! function_exists( 'my_wc_increase_stock_levels' ) ) {
        function my_wc_increase_stock_levels( $order_id ) {
            if ( is_a( $order_id, 'WC_Order' ) ) {
                $order    = $order_id;
                $order_id = $order->get_id();
            } else {
                $order = wc_get_order( $order_id );
            }
    
            // We need an order, and a store with stock management to continue.
            if ( ! $order || 'yes' !== get_option( 'woocommerce_manage_stock' ) || ! apply_filters( 'woocommerce_can_restore_order_stock', true, $order ) ) {
                return;
            }
    
            $changes = array();
    
            // Loop over all items.
            foreach ( $order->get_items() as $item ) {
                if ( ! $item->is_type( 'line_item' ) ) {
                    continue;
                }
    
                // Only increase stock once for each item.
                $product            = $item->get_product();
                $item_stock_reduced = $item->get_meta( '_reduced_stock', true );
    
                if ( ! $item_stock_reduced || ! $product || ! $product->managing_stock() ) {
                    continue;
                }
    
                // Check order status and product tag
                $check_order_status     = array( 'your-order-status' );
                $check_product_tag_slug = 'your-product-tag';
                if ( $order->has_status( $check_order_status ) ) {
                    $tags = wc_get_product_terms( ( $product->get_parent_id() ? $product->get_parent_id() : $product->get_id() ), 'product_tag' );
                    $tags = wp_list_pluck( $tags, 'slug' );
                    if ( in_array( $check_product_tag_slug, $tags ) ) {
                        continue;
                    }
                }
    
                $item_name = $product->get_formatted_name();
                $new_stock = wc_update_product_stock( $product, $item_stock_reduced, 'increase' );
    
                if ( is_wp_error( $new_stock ) ) {
                    /* translators: %s item name. */
                    $order->add_order_note( sprintf( __( 'Unable to restore stock for item %s.', 'woocommerce' ), $item_name ) );
                    continue;
                }
    
                $item->delete_meta_data( '_reduced_stock' );
                $item->save();
    
                $changes[] = $item_name . ' ' . ( $new_stock - $item_stock_reduced ) . '→' . $new_stock;
            }
    
            if ( $changes ) {
                $order->add_order_note( __( 'Stock levels increased:', 'woocommerce' ) . ' ' . implode( ', ', $changes ) );
            }
    
            do_action( 'woocommerce_restore_order_stock', $order );
        }
    }
    

    The code is not very small, but 99% of it is a copy of these two standard WooCommerce functions:
    https://github.com/woocommerce/woocommerce/blob/7.7.0/plugins/woocommerce/includes/wc-stock-functions.php#L123
    https://github.com/woocommerce/woocommerce/blob/7.7.0/plugins/woocommerce/includes/wc-stock-functions.php#L268

    You need to modify only these two lines in the snippet:

    $check_order_status     = array( 'your-order-status' );
    $check_product_tag_slug = 'your-product-tag';
    

    That is, now the snippet will not increase stock on order status change to your-order-status for the products with the your-product-tag tag – you need to set your order status and product tag here.

    in reply to: add custom fields to ean (existing and new) #124497
    Tom Anbinder
    Moderator
    Plugin Support

    Hi, Angelo,

    Do you mean in the “EAN > Print” section? If that’s the case, I think what you need is our [alg_wc_ean_product_meta] shortcode:

    [alg_wc_ean_product_meta key="usbs_stock_location_level_1"]
    [alg_wc_ean_product_meta key="usbs_stock_location_level_2"]
    [alg_wc_ean_product_meta key="usbs_stock_location_level_3"]

    This should go in the “EAN > Print > Template” option.

    Please give it a try and let me know what you think.

    in reply to: Is plugin WPML ready? #124052
    Tom Anbinder
    Moderator
    Plugin Support

    Hi, @kootj-net,

    Would it be possible to share access to your site, so I could log in and check what’s going on (my email is [email protected])?

    in reply to: Print setup not working for labels #122708
    Tom Anbinder
    Moderator
    Plugin Support

    If anyone else is interested – since the plugin v4.7.4, there are new options in our plugin’s “Print > Cell” settings section – “Cell top/left/right/bottom margin” – you can add gaps between cells/labels with them.

    in reply to: Class Name #122617
    Tom Anbinder
    Moderator
    Plugin Support

    Hi, Jay,

    All our plugin emails are Alg_WC_Custom_Email class objects.

    When we add them to WooCommerce via the woocommerce_email_classes filter, we use these keys:

    Alg_WC_Custom_Email
    Alg_WC_Custom_Email_2
    Alg_WC_Custom_Email_3
    ...

    And custom email IDs are:

    alg_wc_custom
    alg_wc_custom_2
    alg_wc_custom_3
    ...

    I hope this helps. Please let me know if you have any questions.

    in reply to: Print setup not working for labels #122349
    Tom Anbinder
    Moderator
    Plugin Support

    Hi, Rebecca,

    Could you please send me a screenshot of your “EAN > Print” settings section? And the resulting PDF?

    P.S. If you wish, I can log in to your site and check what’s going on (my email is [email protected]).

    in reply to: EAN IS NOT DISPLAYED PROPERLY ON THE SINGLE PRODUCT PAGE #122147
    Tom Anbinder
    Moderator
    Plugin Support

    Hi, Frank,

    … the EAN numbers are not shown properly on the single product page…

    Please try adding this to your custom CSS (“Customize > Additional CSS”):

    .sku_wrapper {
        display: block;
    }

    … the numbers are displayed doubled…

    Would it be possible to log in to your site to check what’s going on (my email is [email protected])?

    Tom Anbinder
    Moderator
    Plugin Support

    Update: I’ve just realized we may have a problem with this snippet. Let’s say the customer makes two orders on the same day. Even though the first email will be scheduled, and the second will not (so all ok for now), when three days pass, and the scheduled email is triggered – it won’t be sent because, at this point, the customer already has more than one order. To fix this, please update the plugin to the latest v2.2.8, and change our snippet to:

    add_filter( 'alg_wc_custom_emails_is_enabled', function ( $is_enabled, $email, $object_id, $do_force_send ) {
        if (
            ! $do_force_send && // not "force send", e.g., scheduled
            'alg_wc_custom' === $email->id && // it's custom email #1
            ( $order = wc_get_order( $object_id ) ) && // it's an order email
            ( $customer_id = $order->get_customer_id() ) && // not guest order
            ( $customer = new WC_Customer( $customer_id ) ) && // get customer object
            $customer->get_order_count() > 1 // not first order
        ) {
            // Do NOT send email
            return false;
        }
        return $is_enabled;
    }, 10, 4 );

    Please give it a try and let me know what you think.

    Tom Anbinder
    Moderator
    Plugin Support

    Hi, Liviu,

    Please try this:

    add_filter( 'alg_wc_custom_emails_is_enabled', function ( $is_enabled, $email, $object_id ) {
        if (
            'alg_wc_custom' === $email->id && // it's custom email #1
            ( $order = wc_get_order( $object_id ) ) && // it's an order email
            ( $customer_id = $order->get_customer_id() ) && // not guest order
            ( $customer = new WC_Customer( $customer_id ) ) && // get customer object
            $customer->get_order_count() > 1 // not first order
        ) {
            // Do NOT send email
            return false;
        }
        return $is_enabled;
    }, 10, 3 );

    Let me know if this helps.

    in reply to: Use order meta field as trigger #121795
    Tom Anbinder
    Moderator
    Plugin Support

    Hi,

    We could check the meta each time order is saved – with the woocommerce_after_order_object_save action.

    Try adding this snippet to your site:

    add_action( 'woocommerce_after_order_object_save', function ( $order ) {
        if (
            function_exists( 'alg_wc_ce_send_email' ) &&
            'yes' === $order->get_meta( 'your_meta_key' ) // replace meta key
        ) {
            $custom_email_id = 1; // for the "Custom email #1"
            alg_wc_ce_send_email( $custom_email_id, $order->get_id() );
        }
    } );

    Please let me know what you think.

Viewing 15 posts - 31 through 45 (of 1,178 total)