• Hello, thank you very much for the great and simple plugin, it has been a great help in my routine!

    In my ERP, we`re creating a function that send an email with the link to fill the cart based on internal rules, but we only can get the SKU of the products.

    Is there a way to set the cart link using SKU of the product too? Or even choose if I want to use SKU or Id?
    I`m picturing something like: “https://mysite.com/cart?set_cart_SKU=sku1,2Xsku2,3Xsku3”

    I was trying to change the behavior of the plugin by changing some variable, but I still did not succeed:
    “$product_id = $wpdb->get_var( $wpdb->prepare( “SELECT post_id FROM $wpdb->postmeta WHERE meta_key=’_sku’ AND meta_value=’%s’ LIMIT 1″, $add_to_cart ) );”

    P.S.: My code skills are not so good…=(

    Thank you in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Soft79

    (@josk79)

    Query looks good to me; but to be safe you’d better escape the sku with esc_sql(). You also have to change the regular expression that parses the querystring:

    replace $pattern = '/^(?:(\d+)x)?(\d+)$/i'; with $pattern = '/^(?:(\d+)x)?([-\w\d]+)$/i';

    that would allow sku’s with letters, numbers and hyphens.

    Thread Starter matnog

    (@matnog)

    Thank you for the reply and tip!

    I have tried in many ways but unfortunately it is above my ability with codes, I still can`t make it work.

    I got this query in another plugin that seems like yours and was trying to use in the “soft79-cart-links-for-woocommerce.php”, but I still did not succeed.

    So it does not seem as simple as “changing a variable” as I had thought.

    Therefore, is there a snippet that I can use to achieve that?

    Sorry if I’m asking too much…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set cart link by SKU’ is closed to new replies.