Okay
  Public Ticket #3604713
dynamic rules activation
Closed

Comments

  •  7
    Jose Perez started the conversation

    I need help, I have several dynamic rules that apply on certain product categories, I need to inform customers about the conditions that apply to take advantage of the discount set in the dynamic rule of the category.

    1.- Is there any way either through shortcode or snippet that allows me to inform in the product category archive and on single  product the conditions to take advantage of the discount, for example "Get 10% for the purchase of 5 units in the category of Analog" in the header of the product category archive and in some hook of the product page.

     2.- It is possible to manage a counter to inform the customer how many products are to take advantage of the discount indicated in the dynamic rule, for example "you are 3 units away to take advantage of the 10% discount on the Analog category".

    3.- Once applied the rule currently displays a badge on the product image with the name of the discount activated, is it possible to have a function, snippet or shortcode this text to move it to another location?

  •  1,881
    WebWizards replied

    Hello Jose,

    3.- Once applied the rule currently displays a badge on the product image with the name of the discount activated, is it possible to have a function, snippet or shortcode this text to move it to another location?

    The badges here use the standard Woo / theme badges for "on sale" products, so they are the same as all other badges of products which are on sale.

    I am not sure if you are looking to change this for all on sale products, or only products for which B2BKing adds this (and have a different location for regular on sale products vs b2bking on sale products). It would help if you can clarify that.

    If you're looking to change that badge location in general for all products, it should be relatively easy to do that with some custom CSS. We can assist with it if you can share a link to such a product on your site (so we can check its display with your theme).



    1.- Is there any way either through shortcode or snippet that allows me to inform in the product category archive and on single  product the conditions to take advantage of the discount, for example "Get 10% for the purchase of 5 units in the category of Analog" in the header of the product category archive and in some hook of the product page.

     2.- It is possible to manage a counter to inform the customer how many products are to take advantage of the discount indicated in the dynamic rule, for example "you are 3 units away to take advantage of the 10% discount on the Analog category".

    Currently we do not have a specific feature to show these rules on products. 

    One thing to consider is possibly using the product information table to add this info: https://woocommerce-b2b-plugin.com/docs/custom-information-table-in-product-page/


    Other than that, something could also be custom coded. You could get for example all discount rules that apply to a product for the current user, using this code:

    $discount_rules = b2bking()->get_applicable_rules('discount_everywhere', $product_id);
    $discount_rules = b2bking()->filter_check_rules_apply_current_user($discount_rules);

    There is no built-in feature for it though, so it's needed to custom code something. We can certainly provide you with technical info on this if you are looking to achieve this.


    Kind regards,

    Stefan

  •  7
    Jose Perez replied

    On point 1,2

    Is it possible to have a code snippet, that tells me what dynamic rules the product has registered, I currently have several dynamic rules that apply to the product categories, and I want to display the information of the discounts that can be obtained for the purchase of xx amount of products within the same category.

  •  1,881
    WebWizards replied

    Generally, a variation of this code can get you the rules that apply to a product:

    $discount_rules = b2bking()->get_applicable_rules('discount_everywhere', $product_id);
    if (isset($discount_rules[0]) && $discount_rules !== 'norules'){
        $discount_rules = $discount_rules[0];
        $discount_rules = b2bking()->filter_check_rules_apply_current_user($discount_rules);
    }
    


    Let's say I have the following discount rule, that applies to a category:

    4894916512.png


    I can add the following PHP code snippet to a site, to display the discount rules of a product on each product page - it will also show the category rule:

    add_action('woocommerce_single_product_summary', function(){
        global $post;
        $product_id = $post->ID;
        $discount_rules = b2bking()->get_applicable_rules('discount_everywhere', $product_id);
        if (isset($discount_rules[0]) && $discount_rules !== 'norules'){
            $discount_rules = $discount_rules[0];
            $discount_rules = b2bking()->filter_check_rules_apply_current_user($discount_rules);
        }
        var_dump($discount_rules);
        echo '<br>';
    });
    

    When going to that page, it shows the rule IDs of the rule that apply to it:

    5334345970.png