Posts

Showing posts from June, 2021

get user info in WordPress

$ current_user  = wp_get_current_user(); esc_html( $current_user ->user_login ); esc_html( $current_user ->user_email ) ; esc_html( $current_user ->user_firstname ); esc_html( $current_user ->user_lastname ); esc_html( $current_user ->display_name ); esc_html( $current_user ->ID );

Get Order Id in woocommerce

           global $woocommerce, $post;     $order = new WC_Order($post->ID);      add_action( 'woocommerce_thankyou', 'custom_content_thankyou', 10, 1 ); function custom_content_thankyou( $order) {    echo "This is order ID: ".$order; }

Ajax with Json Data in Vanilla JavaScript

  let setId = id;         let data = {id:setId};         const jsonToString = JSON.stringify(data);    const xhr = new XMLHttpRequest();         xhr.open('POST','https://eteacherbd.com/app-functions/english/build-vocabulary/get-text.php', true);         xhr.setRequestHeader('Content-type', 'application/json');   xhr.onreadystatechange = function () {    if(this.status === 200 ){        const Data = JSON.parse(this.responseText);         getid.innerHTML = Data.id;        getWord.innerHTML = Data.word;       getMeaning.innerHTML = Data.meaning;     } }; xhr.send(jsonToString); Access in php file  <?php  header("Content-Type: application/json");   $jsonData = file_get_contents('php://input');     $data = json_decode($jsonData);        if($data-...

Get Order Info

Image
 global $woocommerce;     $shippingAmout = $woocommerce->cart->get_totals()['shipping_total'];     $productTotal = $woocommerce->cart->get_totals()['subtotal'];     echo "Shipping Charge ".$shippingAmout."<br>";     echo "Only Product Total Price ".$productTotal;

Run Function After Click Order Place Button

  add_action( 'woocommerce_checkout_order_processed', 'after_submit_place_btn', 10, 1 );     function after_submit_place_btn(){        $shipping           = new \WC_Shipping();     $total_shipping = $shipping->get_shipping_classes();     // $total_shipping = $shipping->get_cost();         $value = WC()->cart->cart_contents_total;        // $total_shipping = WC()->session->get( 'shipping_cost' );         // $total_shipping = WC()->cart->calculate_shipping();         setcookie('SHIPPINGJM', $total_shipping,'/');         setcookie('PRICEJM', $value,'/');     }

Display Shipping Cost In String With Money Sing

 add_action('woocommerce_review_order_before_payment','QuadLayers_callback_function'); function QuadLayers_callback_function(){    $shipping_total = WC()->cart->get_cart_shipping_total();     echo $shipping_total; }

Display On Check-page

 add_action('woocommerce_review_order_before_payment','QuadLayers_callback_function'); function QuadLayers_callback_function(){    // Write your code here  }

Add Custom Shipping Fee

function woo_add_cart_fee() {     global $woocommerce;   $woocommerce->cart->add_fee( __('Custom', 'woocommerce'), 5 ); } add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );

Add Shipping Cost

 add_action( 'woocommerce_after_order_notes', 'cpm_woocommerce_checkout_update'); function cpm_woocommerce_checkout_update(){      // WC()->cart->get_cart_shipping_total();     $shipping = wc_cart_totals_shipping_html();         echo $shipping;     }