This file contains 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 | |
/** | |
* Create the function to output the contents of our Dashboard Widget. | |
*/ | |
function wc_orders_dashboard_widget_function() { | |
$args = array( | |
'post_type' => 'shop_order', |
This file contains 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
.complete, .processing, .view { | |
display: block; | |
text-indent: -9999px; | |
position: relative; | |
height: 1em; | |
width: 1em; | |
padding: 0!important; | |
height: 2em!important; | |
width: 2em; | |
} |
This file contains 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 | |
/** | |
* This function include wcodw_style.css file only on dashboard. | |
*/ | |
function wc_my_enqueue_scripts_css() { | |
$screen = get_current_screen(); | |
$screen_id = $screen ? $screen->id : ''; | |
if ( $screen_id == "dashboard" ) { |
This file contains 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 | |
/** | |
* Remove free product from cart when parent product is removed. | |
*/ | |
function remove_product_from_cart() { | |
// Run only in the Cart or Checkout Page | |
if( is_cart() || is_checkout() ) { |
This file contains 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 | |
/** | |
* Show products only of selected category. | |
*/ | |
function get_subcategory_terms( $terms, $taxonomies, $args ) { | |
$new_terms = array(); | |
$hide_category = array( 126 ); // Ids of the category you don't want to display on the shop page | |
This file contains 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 | |
/** | |
* Adding button to mini cart. | |
*/ | |
function woocommerce_widget_shopping_cart_buttons_callback() { | |
echo '<a href="' . esc_url( wc_get_checkout_url() ) . '" class="button wc-forward x-anchor">'. esc_html__( 'Submit Order', 'woocommerce' ) .'</a>'; | |
} | |
add_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_buttons_callback', 20 ); |
This file contains 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 | |
function woocommerce_order_item_get_formatted_meta_data_callback( $formatted_meta ){ | |
foreach ( $formatted_meta as $key => $value ) { | |
$formatted_meta[$key]->display_value = wp_strip_all_tags( $value->display_value ); | |
} | |
return $formatted_meta; | |
} | |
add_filter( "woocommerce_order_item_get_formatted_meta_data", "woocommerce_order_item_get_formatted_meta_data_callback", 10, 1 ); |
This file contains 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 | |
/** | |
* Function to fetch all WooCommerce product ids. | |
*/ | |
function get_all_wc_products_ids() { | |
$args = array( | |
'post_type' => array( 'product' ), | |
'posts_per_page' => -1, | |
'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), // 'all' |
This file contains 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 | |
function add_custom_price( $cart_object ) { | |
$cart_total = 25; // If cart total is more than this value. | |
$free_product_id = 6332; // Set price to 0 of this free product. | |
$carttotal = 0; | |
foreach ( $cart_object->cart_contents as $key => $value ) { | |
$_product = $value['data']; |
This file contains 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 | |
/* | |
* Automatically adding the product to the cart for only specific user roles. | |
*/ | |
function aaptc_add_product_to_cart( $item_key, $product_id ) { | |
$product_category_id = 123; // cricket bat category id | |
$product_cats_ids = wc_get_product_term_ids( $product_id, 'product_cat' ); | |
$user = wp_get_current_user(); // This will fetch current user's role | |
$allowed_roles = array( 'booking_agent', 'perfecth' ); // These are the list of allowed user role. |