How to get vendor name in coupon cycle

MultivendorX

Resolved
Viewing 5 reply threads
  • Author
    Posts
    • #217555
      l.gan
      Participant

      Hello, thanks for the great support!

      Can you help me – I’m using a code that gets a list of all published coupons.
      Coupon Code, Discount Amount, Description.

      HOW to display also: Vendor name, who is assigned the coupon?
      If a vendor is not assigned to a coupon, the coupon should not be displayed in the shortcode.
      If a vendor is assigned to a coupon, the coupon should be displayed in a shortcode and display the vendor’s name.

      Thank you for your help.

      add_shortcode('ac', 'coupon_list' );
      function coupon_list() {
          $coupon_posts = get_posts( array(
              'posts_per_page'   => -1,
              'orderby'          => 'name',
              'order'            => 'asc',
              'post_type'        => 'shop_coupon',
              'post_status'      => 'publish',
          ) );
      
          $coupon_info = []; // Initializing
      
          foreach( $coupon_posts as $coupon_post) {
              $coupon_info[] = array(
                  'code' => $coupon_post->post_name,
                  //'date_expires' => get_post_meta( $coupon_post->ID, 'date_expires', true ),
                  //'expiry_date' => get_post_meta( $coupon_post->ID, 'expiry_date', true ),
                  'amount' => get_post_meta( $coupon_post->ID, 'coupon_amount', true ),
                  //'discount_type' => get_post_meta( $coupon_post->ID,'discount_type', true),
                  'description' => $coupon_post->post_excerpt
              );
          }
          // Display available coupon codes with additional information
          $output = '';
          foreach( $coupon_info as $info ) {
              $output .= 'Code: ' . $info['code'] . ', ' . $info['expiry_date'] .  $info['discount_type'] .', Amount: ' . $info['amount'] . ', Description: ' . $info['description'] . '<br>';
          }
          return $output; // always use return in a shortcode
      }
      Copy
    • #217572

      Hello @l.gan Our team has gone through your shared code and based on that we are providing you with the code to fetch the vendor object below.

      
      $vendor_id = $coupon_post->post_author;
      $vendor = get_mvx_vendor($vendor_id);
      
      Copy

      Now use the earlier shared code in your existing code accordingly to achieve your required flow.

      Let us know if you need any further assistance from our end.

    • #217591
      l.gan
      Participant
      This reply has been marked as private.
    • #217621

      We have already provided you earlier with the code to fetch the vendor data. Now to fetch the vendor name you need to use the below code –

      
      $vendor->page_title
      
      Copy
      • #217638
        l.gan
        Participant

        Thank you so much, amazing support! My issue is resolved.

    • #217639

      Great to hear that. Let us know if you need any further assistance from our end.
      Also, It would be really great if you can give us 5/5 review here: https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor/reviews/#new-post
      This would motivate the team further to do their job more efficiently.

    • #219373

      Hello There, Its been long and we have not heard back from you. We are closing this thread. If you need help or face issue on your end in future please do create a new support ticket.

Viewing 5 reply threads

The topic ‘How to get vendor name in coupon cycle’ is closed to new replies.