Home Forums WoodMart support forum Need help with New productscategory

Need help with New productscategory

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #570742

    gnl-commerce.nl
    Participant

    Currently i have created a category called: Nieuwkomers (Translated new products).
    I want when i add a new product and this is marked as a permanent new item this is automaticly placed by the category: Nieuwkomers..

    I tried coding my way with PHP, but i can’t seem to figure out how to make it work.

    function add_product_to_new_arrivals_category( $post_id ) {
    // Controleer of het product is gemarkeerd als ‘nieuw’
    $is_new = get_post_meta( $post_id, ‘_new_product’, true );

    // Controleer of het product al is toegevoegd aan de ‘Nieuwkomers’ categorie
    $is_in_new_arrivals_category = has_term( ‘nieuwkomers’, ‘product_cat’, $post_id );

    // Als het product is gemarkeerd als ‘nieuw’ en nog niet in de ‘Nieuwkomers’ categorie zit, voeg het dan toe aan de categorie
    if ( $is_new && ! $is_in_new_arrivals_category ) {
    wp_set_post_terms( $post_id, ‘nieuwkomers’, ‘product_cat’, true );
    }
    }

    // Haak in op de actie ‘save_post’ om de functie uit te voeren wanneer een product wordt opgeslagen
    add_action( ‘save_post’, ‘add_product_to_new_arrivals_category’ );

    See link: https://boenderoutdoor.nl/nieuwkomers/

    #570828

    Luke Nielsen
    Keymaster

    Hello,

    You can create a separate page “New Products” in which the “products (grid or carousel)” will be defined with such setting – https://prnt.sc/_crE3Er6HjSq thus products with new labels will be automatically added to that page.

    Kind Regards

    #571491

    gnl-commerce.nl
    Participant

    Alright thanks!

    #571665

    Luke Nielsen
    Keymaster

    Hello,

    You are welcome! In case you need any additional help, I’d be more than happy to assist you.

    Have a good day!

    Kind Regards

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Need help with New productscategory’ is closed to new replies.