Add CSS with disabled attribute/ Hide Update cart before update Item Woocommerce

input[name=”update_cart”]:disabled {
display:none !important;
}

Css for disabled attribute

Advertisements

Add New Admin User in WordPress by MySql Query

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES (‘newadmin’, MD5(‘pass123’), ‘firstname lastname’, ‘email@example.com‘, ‘0’);

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), ‘wp_capabilities’, ‘a:1:{s:13:”administrator”;s:1:”1″;}’);

INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), ‘wp_user_level’, ’10’);

Add remove shipping method when free shipping class is available WooCommerce

add_filter( ‘woocommerce_package_rates’,’hide_shipping_when_free_is_available’);

function hide_shipping_when_free_is_available( $rates, $package ) {
$freeship = array();
$flatship = array();
// Only modify rates if free_shipping is present
$total = WC()->cart->cart_contents_total;
if( $total >= 150 ) {
foreach ( $rates as $rate_id => $rate ) {
if ( ‘free_shipping’ === $rate->method_id ) {
$freeship[ $rate_id ] = $rate;
break;
}
}
foreach ( $rates as $rate_id => $rate ) {

if ( ‘flat_rate’ === $rate->method_id ) {
continue;

}
$flatship[ $rate_id ] = $rate;
}
return ! empty( $freeship ) ? $flatship : $rates;
}else{
return $rates;
}

}

woocommerce add js in payment gateway option

jQuery(function(){
    jQuery( 'body' )
    .on( 'updated_checkout', function() {
          usingGateway();

        jQuery('input[name="payment_method"]').change(function(){
            console.log("payment method changed");
              usingGateway();

        });
    });
});


function usingGateway(){
    console.log(jQuery("input[name='payment_method']:checked").val());
    if(jQuery('form[name="checkout"] input[name="payment_method"]:checked').val() == 'my_gateway'){
        console.log("Using my gateway");
        //Etc etc
    }else{
         console.log("Not using my gateway. Proceed as usual");
    }
}   

Add a surcharge to cart and checkout

function df_add_ticket_surcharge( $cart_object ) {

global $woocommerce;
$specialfeecat = 14; // category id for the special fee
$spfee = 0.00; // initialize special fee
$spfeeperprod = 15; //special fee per product

foreach ( $cart_object->cart_contents as $key => $value ) {

$proid = $value[‘product_id’]; //get the product id from cart
$quantiy = $value[‘quantity’]; //get quantity from cart
$itmprice = $value[‘data’]->price; //get product price

$terms = get_the_terms( $proid, ‘product_cat’ ); //get taxonamy of the prducts
if ( $terms && ! is_wp_error( $terms ) ) :
foreach ( $terms as $term ) {
$catid = $term->term_id;
if( 14 == $catid ) {
$spfee += ($quantiy * 15);
}elseif( 12 == $catid ) {
$spfee += ($quantiy * 10);
}elseif( 87 == $catid ) {
$spfee += ($quantiy * 15);
}
}
endif;
}

if($spfee > 0 ) {

$woocommerce->cart->add_fee( ‘Shipping Cost’, $spfee, true, ‘standard’ );
}

}

add_action( ‘woocommerce_cart_calculate_fees’, ‘df_add_ticket_surcharge’ );