Posts

Showing posts with the label woocommerce

How to add a custom sorting or order by option on category archive or product archive page in woocommerce wordpress

Just copy and paste below code into your theme's functions.php or into your custom plugin file and change option name and value according to your requirement. function rj_add_custom_postmeta_orderby( $sortby ) {     $sortby = array(); // do this for remove all default options        $sortby['grapes'] = __( 'Grapes', 'woocommerce' );     $sortby['main_region'] = __( 'Region', 'woocommerce' );     $sortby['wine_color'] = __( 'Colors', 'woocommerce' );     $sortby['class'] = __( 'Type', 'woocommerce' );     return $sortby; } add_filter( 'woocommerce_default_catalog_orderby_options', 'rj_add_custom_postmeta_orderby' ); add_filter( 'woocommerce_catalog_orderby', 'rj_add_custom_postmeta_orderby' ); function rj_get_catalog_ordering_args( $sort_args ) {             $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : appl...

How to add a custom or new order status in woocommerce wordpress

For add a custom or new order status in woocommerce store. just copy and paste below code into your theme's functions.php or in your custom plugins file. For example i am add a shipping order status for order . // register post status wc-shipping add_action('init','register_shipping_post_status'); function register_shipping_post_status(){         register_post_status( 'wc-shipping', array(             'label'                     => 'Shipping',             'public'                    => true,             'exclude_from_search'       => false,          ...

How to change user id on checkout page for assign order to different user in woocommerce wordpress

Just copy and paste below code into your theme's functions.php file or in your custom plugin file function rj_replace_user_id_with_session_id(){     if(!session_id()){         session_start();     }     if(isset($_SESSION['order_replace_by_user_id'])){            return $_SESSION['order_replace_by_user_id']; // return user id you want to assign order     } } add_filter( 'woocommerce_checkout_customer_id', 'rj_replace_user_id_with_session_id' );

How to add a custom tab for single product tabs in woocommerce wordpress

For add a custom tab in single product page tabs just copy and paste below code into your theme's functions.php file add_filter( 'woocommerce_product_tabs', 'rj_single_product_additional_tab' ); function rj_single_product_additional_tab( $tabs ) { $tabs['additional_info'] = array( 'title' => __( 'Additional Info', 'woocommerce' ), 'priority' => 1, 'callback' => 'rj_single_product_additional_tab_callback' ); return $tabs; } function rj_single_product_additional_tab_callback() { global $post,$product,$wpdb; // your display content here }

How to change cart product price dynamically in woocommerce worpdress

For change cart product price dynamically just copy and paste below code in your theme's functions.php and change code according to your need. add_action( 'woocommerce_get_price', 'rj_bill_payment_price_change_for_customer',10, 2 ); function rj_bill_payment_price_change_for_customer( $price, $product ) {     global $wpdb,$post,$woocommerce;     // do stuff here as per your need     return $price; }

How to change realted product thumbnail size in woocommerce single product page wordpress

For change the related product thumbnail size in single product page woocommerce paste below code in your theme's functions.php file below code is tested and works fine. add_action( 'after_setup_theme', 'rj_remove_loop_thumbnail_filter', 10 ); function rj_remove_loop_thumbnail_filter() {     remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); } add_filter('woocommerce_related_products_args','rj_related_product_args'); function rj_related_product_args($query_args) {     if( is_singular( 'product' ) ) {    if( ! empty( $query_args ) ) {             set_query_var( 'related_products', true );         }     }     return $query_args; } remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); add_action(...

How to add a custom email functionality in woocommerce,wordpress for example new email template for shipping order

How to add a custom email template option in woocommerce Just copy and paste below code in your theme's functions.php <?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly /**  * A custom shipping WooCommerce Email class  *  * @since 0.1  * @extends \WC_Email  */  if(!class_exists('WC_Shipping_Email'))  {     include_once WP_PLUGIN_DIR.'/woocommerce/includes/emails/class-wc-email.php' ; class WC_Shipping_Email extends WC_Email {     public function __construct() {     if ( ! class_exists('Emogrifier') ){             require_once( 'includes/emogrifier/Emogrifier.php' );         }     $this->id = 'wc_shipping_email';         $this->title = 'Shipping Order';         $this->description = 'Shipping Order Notification emails are sent ...

How to change related product thumbnail size for display in single product page woocommerce wordpress -Solved

How to change related product thumbnail size for display in single product page woocommerce wordpress Solved below code is tested and works fine. add_action( 'after_setup_theme', 'rj_remove_loop_thumbnail_filter', 10 ); function rj_remove_loop_thumbnail_filter() {     remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); } add_filter('woocommerce_related_products_args','rj_related_product_args'); function rj_related_product_args($query_args) {     if( is_singular( 'product' ) ) {    if( ! empty( $query_args ) ) {             set_query_var( 'related_products', true );         }     }     return $query_args; } remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); add_action( 'woocommerce_before_shop...

How to add a custom field in custom taxonomy or how to add a image field for custom taxonomy like woocommerce produc_cat in wordpress

How to add a custom field in custom taxonomy or how to add a image field for custom taxonomy like woocommerce produc_cat in wordpress For add a custom field in custom taxonomy or add a image field for custom taxonomy just copy below code and add it into your theme's functions.php file and change a taxonomy slug as per your need. // actual action for add add_action( '{custom-taxonomy-slug}_add_form_fields', 'rj_video_categories_add_category_fields' ); //actual action for edit  add_action( '{custom-taxonomy-slug}_edit_form_fields','rj_video_categories_edit_category_fields'  ); add_action( 'video-categories_add_form_fields', 'rj_video_categories_add_category_fields' ); add_action( 'video-categories_edit_form_fields','rj_video_categories_edit_category_fields'  ); function rj_video_categories_add_category_fields() { global $wpdb; ?> <div class="form-field"> <label><?php _e...

How to add a custom product page dropdown option in front end shop or categories pages in woocommerce wordpress

How to give a option to customer for display product as they want For add a custom dropdown on shop or category page , paste below code to your functions.php file of your current active theme. // below action add a new custom dropdown box to shop or category page add_action( 'woocommerce_before_shop_loop', 'rj_product_per_page_dropdown', 25 ); function rj_product_per_page_dropdown() {     global $wp_query,$woocommerce;         $action = '';         $cat     = '';         $cat     = $wp_query->get_queried_object();         $query_string = ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . add_query_arg( array( 'rj_pro_page' => false ), $_SERVER['QUERY_STRING'] ) : null;         if ( isset( $cat->term_id ) && isset( $cat->taxonomy ) ) :         ...

How to add a custom taxonomy field in woocommerce product category or any other custom taxonomy in wordpress

For add a custom taxonomy  field in product category or any other custom taxonomy Add below code in functions.php file of your theme. function product_cat_add_video_field_rj() {         ?>     <div class="form-field">         <label for="term_meta[video_link]"><?php _e( 'Video Link', 'flatsome' ); ?></label>         <input type="text" name="term_meta[video_link]" id="term_meta[video_link]" value="">         <p class="description"><?php _e( 'Enter a Video Link','flatsome' ); ?></p>     </div> <?php } function product_cat_edit_video_field_rj($term) {     $t_id = $term->term_id;     $term_meta = get_option( "taxonomy_$t_id" ); ?>     <tr class="form-field">     <th scope="row" valign="top"><labe...

How to add custom checkout fields in woocommerce wordpress

for add a custom field in checkout form in woocommerce use below code and customize as per your need. // below filter use for display field at frontend side add_filter( 'woocommerce_shipping_fields' , 'rj_shipping_phone_field' ); function rj_shipping_phone_field( $fields ) {       $fields['shipping_phone'] = array(         'label'         => __( 'Phone', 'woocommerce' ),         'required'      => true,         'class'         => array( 'form-row-first' ),         'clear'         => true,         'validate'      => array( 'phone' ),     );     return $fields; } // below filter use for display custom field in admin side add_filter( 'woocommerce_admin_shipping_fields' , 'rj_admin_shipping_phone_field' ); function rj_admin_shipping_pho...

How to update product variation in cart-review page in woocommerce , wordpress

Today i was searched for how to update cart product's  variation on cart-review page and checkout page, after searching a lot didnt get any best solution so i made this script for me.. you need to call your action after all cart page or checkout page request call , so i setted 99 as third parameter in add_action ; below is example code which i made for my client site add_action('init','update_cart_product_rj_funciton',99);  function update_cart_product_rj_funciton() {         global $wpdb,$woocommerce;         if(isset($_REQUEST['cart_update_variation']) && wp_verify_nonce($_REQUEST['cart_update_variation'],'cart_item_variation_update'))     {                 if($_REQUEST['product_id']!='' && $_REQUEST['cart_id']!='')         {             $cart_pro_key = '';             ...