Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('woocommerce_single_product_summary', function() {
- echo do_shortcode('[coupon_applicable_on_product]');
- });
- add_shortcode('coupon_applicable_on_product', function($attr) {
- global $WCFM, $post;
- if( !apply_filters( 'wcfm_is_pref_store_coupons', true ) ) return;
- if ( !is_product() || !function_exists( 'wc_coupons_enabled' ) || ( function_exists( 'wc_coupons_enabled' ) && !wc_coupons_enabled() ) ) return;
- $store_id = $post->post_author;
- if( !$store_id ) return;
- $is_store_offline = get_user_meta( $store_id, '_wcfm_store_offline', true );
- if ( $is_store_offline ) return;
- $is_disable_vendor = get_user_meta( $store_id, '_disable_vendor', true );
- if ( $is_disable_vendor ) return;
- if( !$WCFM->wcfm_vendor_support->wcfm_vendor_has_capability( $store_id, 'manage_coupons' ) ) return;
- $coupon_args = array(
- 'posts_per_page' => -1,
- 'offset' => 0,
- 'category' => '',
- 'category_name' => '',
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'include' => '',
- 'exclude' => '',
- //'meta_key' => 'show_on_store',
- //'meta_value' => 'yes',
- 'post_type' => 'shop_coupon',
- 'post_mime_type' => '',
- 'post_parent' => '',
- 'author' => $store_id,
- 'post_status' => array('publish'),
- 'suppress_filters' => 0
- );
- $wcfm_store_coupons = get_posts( $coupon_args );
- if( empty( $wcfm_store_coupons ) ) return;
- $content = '';
- foreach( $wcfm_store_coupons as $wcfm_store_coupon ) {
- $wc_coupon = new WC_Coupon( $wcfm_store_coupon->ID );
- if ( $wc_coupon->get_date_expires() && ( current_time( 'timestamp', true ) > $wc_coupon->get_date_expires()->getTimestamp() ) ) continue;
- $product_ids = explode(',', get_post_meta( $wcfm_store_coupon->ID, 'product_ids', true));
- $excluded_product_ids = explode(',', get_post_meta( $wcfm_store_coupon->ID, 'exclude_product_ids', true));
- if( !empty($excluded_product_ids) && in_array($post->ID, $excluded_product_ids) ) continue;
- if( !empty($product_ids) && !in_array($post->ID, $product_ids) ) continue;
- $free_shipping = ( get_post_meta( $wcfm_store_coupon->ID, 'free_shipping', true) == 'yes' ) ? 'enable' : '';
- if( $free_shipping ) {
- $content .= '<span class="wcfmmp-store-coupon-single tips text_tip" data-tip="' . __( 'FREE Shipping Coupon', 'wc-multivendor-marketplace' ) . ($wc_coupon->get_date_expires() ? '<br>' . __( 'Expiry Date: ', 'wc-multivendor-marketplace' ) . $wc_coupon->get_date_expires()->date_i18n( 'F j, Y' ) : '' ) . '<br>' . $wcfm_store_coupon->post_excerpt . '">' . $wcfm_store_coupon->post_title . '</span>';
- } else {
- $content .= '<span class="wcfmmp-store-coupon-single tips text_tip" data-tip="' . esc_html( wc_get_coupon_type( $wc_coupon->get_discount_type() ) ) . ': ' . esc_html( wc_format_localized_price( $wc_coupon->get_amount() ) ) . ($wc_coupon->get_date_expires() ? '<br>' . __( 'Expiry Date: ', 'wc-multivendor-marketplace' ) . $wc_coupon->get_date_expires()->date_i18n( 'F j, Y' ) : '' ) . '<br>' . $wcfm_store_coupon->post_excerpt . '">' . $wcfm_store_coupon->post_title . '</span>';
- }
- }
- if($content) {
- echo '<div class="wcfmmp_store_coupons">' . $content . '</div>';
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement