• Resolved Charles

    (@correctshop)


    Hi,
    I really need help to apply the force coupon to a specific category or product. I have been trying to work with the following code I found in Stack Overflow by adding it to the functions.php in current theme folder, but it brings the whole site down:

    // Force Coupon codes for Woocommerce
    add_action(‘woocommerce_check_cart_items’, ‘mandatory_coupon_code’);
    function mandatory_coupon_code()
    {
    // set Here your categories IDs, slugs or names
    $categories = array(18,19,87);
    $found = false;

    // Loop through cart items
    foreach ( WC()->cart->get_cart() as $cart_item )
    if( has_term( $categories, ‘product_cat’, $cart_item[‘product_id’] ) ){
    // Product category found in cart items
    $found = true;
    // Exit from loop
    break;
    }
    }
    $coupons = WC()->cart->get_applied_coupons();

    // The Notice is displayed for that product categories when no mandatory coupon has been entered
    if( count( $coupons ) > 0 && $found )
    wc_add_notice( __( ‘A coupon code is mandatory for this product.’, ‘woocommerce’ ), ‘error’ );

    I am running the latest version of both WordPress and Woocommerce.
    Please could you help me?

    The page I need help with: [log in to see the link]

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

    (@kowsar89)

    It seems like you need additional customization which isn’t covered by this plugin.

    If you need my professional customization service you can ask for a quote from here: https://kowsarhossain.com/contact/

    Thread Starter Charles

    (@correctshop)

    Thank you for the reply, but I’m afraid we do not have the budget for that. I will have to try and to find the solution somehow. Thanks anyway:)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Specific Category’ is closed to new replies.