Advertisement
palsushobhan

wcfm-store-products-shortcode-on-single-product-page

Jan 16th, 2023
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. add_shortcode('wcfm_store_products', function($attr) {
  2.     global $post;
  3.     $product_id = '';
  4.     $store_id = '';
  5.     if ( is_product() && $post && is_object($post) ) {
  6.         $product_id = $post->ID;
  7.         $store_id = $post->post_author;
  8.     }
  9.     if(! $store_id || ! $product_id ) return '';
  10.     if ( isset( $attr['limit'] ) && !empty( $attr['limit'] ) ) {
  11.         $limit = absint($attr['limit']);
  12.         echo do_shortcode('[products store="'.$store_id.'" limit="'.$limit.'"]');
  13.     } else {
  14.         echo do_shortcode('[products store="'.$store_id.'"]');
  15.     }
  16. });
  17.  
  18. add_filter('woocommerce_shortcode_products_query', function ($query_args, $atts, $loop) {
  19.     global $post;
  20.     if ( is_product() && $post && is_object($post) ) {
  21.         $product_id = $post->ID;
  22.         $store_id = $post->post_author;
  23.     }
  24.     if(! $store_id || ! $product_id ) return '';
  25.     $query_args['post__not_in'] = (array)$product_id;
  26.     return $query_args;
  27. }, 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement