Including a Customized Initialize File with a wordpress header

It’s not clear where you need to add this additional code. But I would assume that it is in ‘include’-type files that you need to run in the portion of the generated page. So, to do that, use the add_action(‘wp_head’,’your-function-name’) to load your external function file: add_action(‘wp_head’,’include_my_include’); function include_my_include() { include get_template_directory() . ‘your-function-file.php’; return; … Read more

WooCommerce related products load random posts per page

You need to change the value of $orderby. Maybe the current value of $orderby is rand ‘orderby’ => $orderby, Now you need to change the value of **orderby => ” ** according to your need. for example ‘orderby’ => ‘title’ ‘orderby’ => ‘menu_order title’ ‘orderby’ => ‘comment_count’ ‘orderby’ => ‘meta_value_num’ ‘orderby’ => ‘title menu_order’ Order … Read more

Replace “Add to cart” by a link to contact page on specific product

You can try this. I think it works fine. /*PUT THIS IN YOUR THEME FUNCTIONS FILE*/ /*STEP 1 – REMOVE ADD TO CART BUTTON ON PRODUCT ARCHIVE (SHOP) */ add_action(‘init’,’remove_loop_button’); function remove_loop_button(){ remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 ); } /*STEP 2 -ADD NEW BUTTON THAT LINKS TO PRODUCT PAGE FOR EACH PRODUCT */ add_action(‘woocommerce_after_shop_loop_item’,’replace_add_to_cart’); function replace_add_to_cart() … Read more

login or register then access woocommerce website

You can use “template_redirect” action to check if the current user is logged in or not then redirect the user to my-account page if not. add_action( ‘template_redirect’, function() { $url_parts = array_filter( explode( “https://wordpress.stackexchange.com/”, $_SERVER[‘REQUEST_URI’] ), ‘strlen’ ); if ( ! is_user_logged_in() && ( end( $url_parts ) != ‘my-account’ ) ) { wp_redirect( home_url( ‘/my-account’ … Read more