Category: WooCommerce

Change WooCommce Text

add_filter( ‘gettext’, ‘my_text_strings’, 20, 3 );

function my_text_strings( $translated_text, $text, $domain ) {

switch ( $translated_text ) {

case ‘View Cart’ :

$translated_text = __( ‘View Services’, ‘woocommerce’ );break;

case ‘Update Cart’ :

$translated_text = __( ‘Update Services’, ‘woocommerce’ );break;

case ‘Cart totals’ :

$translated_text = __( ‘Services totals’, ‘woocommerce’ );break;

}

return $translated_text;

}

add_filter ( ‘wc_add_to_cart_message’, ‘wc_add_to_cart_message_filter’, 10, 2 );
function wc_add_to_cart_message_filter($message, $product_id = null) {
$titles[] = get_the_title( $product_id );

$titles = array_filter( $titles );
$added_text = sprintf( _n( ‘%s has been successfully added to your Services.’, ‘%s have been added to your Services.’, sizeof( $titles ), ‘woocommerce’ ), wc_format_list_of_items( $titles ) );

$message = sprintf( ‘%s <a href=”%s” class=”button”>%s</a>&nbsp;<a href=”%s” class=”button”>%s</a>’,
esc_html( $added_text ),
esc_url( wc_get_page_permalink( ‘checkout’ ) ),
esc_html__( ”, ‘woocommerce’ ),
esc_url( wc_get_page_permalink( ‘cart’ ) ),
esc_html__( ‘View Services’, ‘woocommerce’ ));

return $message;
}

Advertisements

After updated cart totals Ajax Woocommerce

jQuery( document.body ).on( ‘updated_cart_totals’, function() {

jQuery( document.body ).on( ‘updated_cart_totals’, function() {

jQuery(“#shipping_method_0”).prepend(“<option value=” selected=’selected’>Select Your Shipping Option</option>”);

console.log( ‘cart updated’ );

} );

Remove WooCommerce styles and scripts

Remove WooCommerce default css and js of lightbox then implement any plugins like:-

  1. Twist – Woocommerce Product Gallery Slider
  2. Responsive Lightbox

 

/* Remove WooCommerce styles and scripts. */
function woo_remove_lightboxes() {

// Styles
wp_dequeue_style( ‘woocommerce_prettyPhoto_css’ );

// Scripts
wp_dequeue_script( ‘prettyPhoto’ );
wp_dequeue_script( ‘prettyPhoto-init’ );
wp_dequeue_script( ‘fancybox’ );
wp_dequeue_script( ‘enable-lightbox’ );
}

add_action( ‘wp_enqueue_scripts’, ‘woo_remove_lightboxes’, 99 );

Remove All products or attributes with SQL commands WooCommerce

Remove all attributes from WooCommerce

DELETE FROM wp_terms WHERE term_id IN 
(SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%');
DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%';
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN 
(SELECT term_taxonomy_id FROM wp_term_taxonomy);

Delete all WooCommerce products

DELETE FROM wp_term_relationships WHERE object_id IN 
(SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN 
('product','product_variation'));
DELETE FROM wp_posts WHERE post_type IN ('product','product_variation');

Delete orphaned postmeta

DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL