Last active
February 8, 2024 13:34
-
-
Save josanua/7ac10f2213d714aad77a37635d94293e to your computer and use it in GitHub Desktop.
woo helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Custom templates, Overrade template | |
https://docs.woocommerce.com/document/template-structure/ | |
// Get order info on thankyou page | |
https://businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/ | |
// Get Order ID | |
$order->get_id(); | |
// Get Order Totals $0.00 | |
$order->get_formatted_order_total(); | |
$order->get_cart_tax(); | |
$order->get_currency(); | |
$order->get_discount_tax(); | |
$order->get_discount_to_display(); | |
$order->get_discount_total(); | |
$order->get_fees(); | |
$order->get_formatted_line_subtotal(); | |
$order->get_shipping_tax(); | |
$order->get_shipping_total(); | |
$order->get_subtotal(); | |
$order->get_subtotal_to_display(); | |
$order->get_tax_location(); | |
$order->get_tax_totals(); | |
$order->get_taxes(); | |
$order->get_total(); | |
$order->get_total_discount(); | |
$order->get_total_tax(); | |
$order->get_total_refunded(); | |
$order->get_total_tax_refunded(); | |
$order->get_total_shipping_refunded(); | |
$order->get_item_count_refunded(); | |
$order->get_total_qty_refunded(); | |
$order->get_qty_refunded_for_item(); | |
$order->get_total_refunded_for_item(); | |
$order->get_tax_refunded_for_item(); | |
$order->get_total_tax_refunded_by_rate_id(); | |
$order->get_remaining_refund_amount(); | |
// Get Order Items | |
$order->get_items(); | |
$order->get_items_key(); | |
$order->get_items_tax_classes(); | |
$order->get_item(); | |
$order->get_item_count(); | |
$order->get_item_subtotal(); | |
$order->get_item_tax(); | |
$order->get_item_total(); | |
$order->get_downloadable_items(); | |
// Get Order Lines | |
$order->get_line_subtotal(); | |
$order->get_line_tax(); | |
$order->get_line_total(); | |
// Get Order Shipping | |
$order->get_shipping_method(); | |
$order->get_shipping_methods(); | |
$order->get_shipping_to_display(); | |
// Get Order Dates | |
$order->get_date_created(); | |
$order->get_date_modified(); | |
$order->get_date_completed(); | |
$order->get_date_paid(); | |
// Get Order User, Billing & Shipping Addresses | |
$order->get_customer_id(); | |
$order->get_user_id(); | |
$order->get_user(); | |
$order->get_customer_ip_address(); | |
$order->get_customer_user_agent(); | |
$order->get_created_via(); | |
$order->get_customer_note(); | |
$order->get_address_prop(); | |
$order->get_billing_first_name(); | |
$order->get_billing_last_name(); | |
$order->get_billing_company(); | |
$order->get_billing_address_1(); | |
$order->get_billing_address_2(); | |
$order->get_billing_city(); | |
$order->get_billing_state(); | |
$order->get_billing_postcode(); | |
$order->get_billing_country(); | |
$order->get_billing_email(); | |
$order->get_billing_phone(); | |
$order->get_shipping_first_name(); | |
$order->get_shipping_last_name(); | |
$order->get_shipping_company(); | |
$order->get_shipping_address_1(); | |
$order->get_shipping_address_2(); | |
$order->get_shipping_city(); | |
$order->get_shipping_state(); | |
$order->get_shipping_postcode(); | |
$order->get_shipping_country(); | |
$order->get_address(); | |
$order->get_shipping_address_map_url(); | |
$order->get_formatted_billing_full_name(); | |
$order->get_formatted_shipping_full_name(); | |
$order->get_formatted_billing_address(); | |
$order->get_formatted_shipping_address(); | |
// Get Order Payment Details | |
$order->get_payment_method(); | |
$order->get_payment_method_title(); | |
$order->get_transaction_id(); | |
// Get Order URLs | |
$order->get_checkout_payment_url(); | |
$order->get_checkout_order_received_url(); | |
$order->get_cancel_order_url(); | |
$order->get_cancel_order_url_raw(); | |
$order->get_cancel_endpoint(); | |
$order->get_view_order_url(); | |
$order->get_edit_order_url(); | |
// Get Order Status | |
$order->get_status(); | |
// source: https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html | |
// get product meta data, get data | |
get_post_meta(123); // general WP | |
// Get product metadata using WooCommerce functions, get product data, get data | |
$product = wc_get_product( 123 ); | |
$product_metadata = $product->get_meta( 'custom_field_key' ); | |
// Remove Related products | |
add_filter('woocommerce_product_related_posts_query', '__return_empty_array', 100); | |
// Removes Order Notes Title - Additional Information & Notes Field | |
add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 ); | |
// Remove the additional information tab | |
add_filter( 'woocommerce_product_tabs', 'bbloomer_remove_product_tabs', 98 ); | |
function bbloomer_remove_product_tabs( $tabs ) { | |
unset( $tabs['additional_information'] ); | |
return $tabs; | |
} | |
// Customize checkout page | |
https://rudrastyh.com/woocommerce/thank-you-page.html | |
hook woocommerce_endpoint_order-received_title - "Order received" text, | |
hook woocommerce_thankyou_order_received_text – "Thank you. Your order has been received." | |
// Custom thank you checkout message | |
add_filter( 'woocommerce_thankyou_order_received_text', 'custom_misha_thank_you_title' ); | |
function custom_misha_thank_you_title( $old_title ){ | |
return 'Lorem text'; | |
} | |
// Change Status Automatically to Complete (for virtual products) | |
https://www.tychesoftwares.com/how-to-automatically-complete-woocommerce-orders-when-they-go-to-the-processing-status/ | |
https://chrislema.com/automating-woocommerce-order-status-changes/ | |
// Change Status Automatically to Complete | |
add_action('woocommerce_order_status_changed', 'ts_auto_complete_virtual'); | |
function ts_auto_complete_virtual($order_id){ | |
if ( ! $order_id ) { | |
return; | |
} | |
global $product; | |
$order = wc_get_order( $order_id ); | |
if ($order->data['status'] == 'processing') { | |
$virtual_order = null; | |
if ( count( $order->get_items() ) > 0 ) { | |
foreach( $order->get_items() as $item ) { | |
if ( 'line_item' == $item['type'] ) { | |
$_product = $order->get_product_from_item( $item ); | |
if ( ! $_product->is_virtual() ) { | |
// once we find one non-virtual product, break out of the loop | |
$virtual_order = false; | |
break; | |
} | |
else { | |
$virtual_order = true; | |
} | |
} | |
} | |
} | |
// if all are virtual products, mark as completed | |
if ( $virtual_order ) { | |
$order->update_status( 'completed' ); | |
} | |
} | |
} | |
// Get product id on checkout process in WooCommerce [duplicate] | |
https://stackoverflow.com/questions/41104409/get-in-woocommerce-cart-the-product-id-of-a-cart-item | |
// checkout form billing, get product id in biling page | |
// Custom, get specific id of a Free product type to make some text changes | |
$counter_p_items = 0; | |
$value_if_id_exists = false; | |
foreach( WC()->cart->get_cart() as $cart_item ){ | |
if ($cart_item['product_id'] == 2513) { | |
$value_if_id_exists = true; | |
} | |
$counter_p_items++; | |
} | |
// change this text if is one sinle product of Free type | |
if ($counter_p_items == 1 && $value_if_id_exists === true ) : ?> | |
<h3><?php esc_html_e( 'Register for your FREE Wedding Box below:', 'woocommerce' ); ?></h3> | |
<?php else : ?> | |
<h3><?php esc_html_e( 'Billing details', 'woocommerce' ); ?></h3> | |
<?php endif; ?> | |
<?php | |
// get product id | |
global $product; | |
$id = $product->get_id(); | |
// get product meta data | |
get_post_meta(114524); | |
// Get product metadata using WooCommerce functions | |
$product = wc_get_product( 123 ); | |
$product_metadata = $product->get_meta( 'custom_field_key' ); | |
// work with db | |
// https://www.hardworkingnerd.com/woocommerce-finding-products-in-the-database/ | |
SELECT * FROM `wp_postmeta` WHERE `post_id` = 133191; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment