php - Woocommerce related product array with user input -


i using following code footer of single-product.php page in woocommerce (i've created "related products" section) , wondering if there way can alter make possible admin able add values product admin page; want products show closer related products instead of totally random ones.

is there way can create custom field product id or tag , add custom field orderby value products/tags have better change of showing vs. random products?

if not, there else can do? looking way allow admin choose closer related products appear.

$args = apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => 5, 'orderby' => rand, 'post__in' => $related, 'post__not_in' => array( $product->id ) ) );

here related-footer.php file complete code includes above snippet.

yes can achieve task following approach:

create custom field product want display set of desired related products custom field name "wdm_related_products" set value comma separated list of product ids eg. 46,15,687,21,48. update product.

add following code in functions.php of user child theme or custom plugin.

add_filter('woocommerce_related_products_args','wdm_custom_related_products',99,1);  function wdm_custom_related_products($array){ global $product; if(get_post_meta($product->,'wdm_related_products',true)){ $related=get_post_meta($product->id,'wdm_related_products',true); $array=array(     'post_type'            => 'product',     'ignore_sticky_posts'  => 1,     'no_found_rows'        => 1,     'posts_per_page'       => 5,     'orderby'              => rand,     'post__in'             => $related,     'post__not_in'         => array( $product->id ) ); } return $array; } 

let me know it resolved issue.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -