Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]

The following hooked functions will allow you to make everything purchasable: // Change all products stock statuses to ‘instock’ add_filter( ‘woocommerce_product_get_stock_status’, ‘filter_get_stock_status_callback’, 10, 2 ); add_filter( ‘woocommerce_product_variation_get_stock_status’, ‘filter_get_stock_status_callback’, 10, 2 ); function filter_get_stock_status_callback( $stock_status, $product ){ return is_admin() ? $stock_status : ‘instock’; } // Enable backorders on all products add_filter( ‘woocommerce_product_get_backorders’, ‘filter_get_backorders_callback’, 10, 2 ); … Read more

Output a WooCommerce product custom field in WooCommerce using get_post_meta()

There are some errors as get_post_meta() first argument need to be a defined product ID here (and in your code post_ID is not even dynamic variable and will not give anything)… Try the following: <?php function check_gtin(){ if ( $gtin = get_post_meta(get_the_id(), ‘gtin’, true) ){ echo “gtin13:”. $gtin; } else { echo ‘identifier_exits:false’; } } … Read more

Displaying Logged-In User Name and avatar in WordPress Menu

You can use “get_avatar” function to display avatar in menu with user name. Please try code given below: add_filter( ‘wp_nav_menu_objects’, ‘my_dynamic_menu_items’, 10 ); function my_dynamic_menu_items( $menu_items ) { foreach ( $menu_items as $menu_item ) { if ( strpos($menu_item->title, ‘#profile_name#’) !== false) { $menu_item->title = str_replace(“#profile_name#”, wp_get_current_user()->user_login .’ ‘. get_avatar( wp_get_current_user()->user_email, 50), $menu_item->title); } } return … Read more

Generate permalinks

The second argument of wp_unique_post_slug filter is post id. You can utilize that to generate the slug only once while creating the post for the first time. Method 1: add_filter( ‘wp_unique_post_slug’, ‘unique_slug_108286’, 10, 2 ); function unique_slug_108286( $slug, $postId ) { if ( ! $postId ) { $n = 4; $slug = bin2hex( random_bytes( $n … Read more

New Plugin Review

Now I’ve seen your code, I think the reviewer is wrong: they’re talking about the form in agg-as-options.php, which is handled the way I describe below except they’re wrong: the form is processed in the agg_options function, not outside of a function as they say this is only shown and processed on the admin aggregate-options … Read more