Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
webtoffee-git / function.php
Created February 27, 2024 03:53
To enable the display of all newly created coupons in the My Account section - By WebToffee (Smart Coupon For WooCommerce)
<?php //Do not add this line of code
add_action( 'woocommerce_new_coupon', 'wbte_sc_show_new_coupon_in_my_account', 20 );
add_action( 'woocommerce_process_shop_coupon_meta', 'wbte_sc_show_new_coupon_in_my_account', 20 );
function wbte_sc_show_new_coupon_in_my_account( $coupon_id ) {
$location_data = get_post_meta( $coupon_id , '_wc_make_coupon_available', true );
if ( $location_data ) {
$locations = explode( ',', $location_data );
if ( ! in_array( 'my_account', $locations ) ) {
@webtoffee-git
webtoffee-git / function.php
Last active February 21, 2024 09:45
Snippet to remove extension from image URL while importing - By WebToffee (Product Import Export Plugin for WooCommerce)
<?php //Do not copy this line of code
add_filter('wt_woocommerce_product_importer_pre_parse_data', 'wt_alter_image_urls');
function wt_alter_image_urls($data) {
// Check if 'images' key exists in the data array
if (isset($data['images'])) {
// Split the images string into an array
$image_urls = explode(', ', $data['images']);
@webtoffee-git
webtoffee-git / function.php
Created February 13, 2024 08:48
To rectify the conflict with Packeta plugin - By WebToffee (Smart Coupon For Woo commerce Plugin)
<?php //Do not copy this line of code
add_filter( 'wbte_sc_clear_error_before_coupon_auto_apply', '__return_false' );
@webtoffee-git
webtoffee-git / functions.php
Last active March 11, 2024 07:40
Code to make the plugin compatible with Google Consent Mode V2 - By WebToffee (GDPR Cookie Consent)
<?php //Do not copy this line of code
add_action('wp_head', 'wt_cli_consent_mode_integration', 9);
function wt_cli_consent_mode_integration() {
if (!class_exists('Cookie_Law_Info')) {
return;
}
$cli_bypass = isset($_GET['cli_bypass']) ? 1 : 0;
$cli_advertisement_cookie = isset($_COOKIE['cookielawinfo-checkbox-advertisement']) ? $_COOKIE['cookielawinfo-checkbox-advertisement'] : 'no';
$cli_functional_cookie = isset($_COOKIE['cookielawinfo-checkbox-functional']) ? $_COOKIE['cookielawinfo-checkbox-functional'] : 'no';
@webtoffee-git
webtoffee-git / functions.php
Created February 8, 2024 05:46
Code to display Product Wise Discount and Discount Percentage in WooCommerce Invoices - By WebToffee
<?php //Do not copyt this line of code
add_filter('wf_pklist_alter_product_table_head', 'wt_pklist_add_product_column', 10, 3);
function wt_pklist_add_product_column($columns_list_arr, $template_type, $order) {
if( 'invoice' == $template_type ) {
$out=array();
foreach ( $columns_list_arr as $key => $value ) {
$out[$key]=$value;
if('price' == $key || '-price' == $key ) {
$out['wfte_product_table_discount_amount']=__('Discount Amount');
$out['wfte_product_table_discount_percentage']=__('Discount Percentage');
@webtoffee-git
webtoffee-git / functions.php
Created February 7, 2024 05:48
Remove the coupon field on adding products from specific categories - By WebToffee
<?php //Do not copy this line of code
add_filter( 'woocommerce_cart_item_class', function($excisting_class, $cart_item, $cart_item_key ){
$product = $cart_item['data'];
$categories = $product->get_category_ids();
$prefix = "wt_sc_product_category_";
$categories = array_map(function($element) use ($prefix) {
return $prefix . $element;
}, $categories);
$categories = implode(" ", $categories);
return $excisting_class . ' ' . $categories;
@webtoffee-git
webtoffee-git / function.php
Created February 7, 2024 05:15
Alter the font-family in PDF invoice while using dompdf - By WebToffee (WooCommerce PDF Invoices, Packing slips, and Credit notes )
<?php //Do not copy this line of code
add_filter('wf_pklist_add_custom_css','wt_pklist_alter_the_css_in_templates',10,3);
function wt_pklist_alter_the_css_in_templates($custom_css,$template_type,$template_for_pdf)
{
if("invoice" === $template_type)
{
$custom_css.='*{font-family: serif !important;}'; // change the font family, and make sure your language in this font is supported in pdf. This will work only on domPdf
}
return $custom_css;
}
@webtoffee-git
webtoffee-git / function.php
Created February 6, 2024 10:16
Alter the print invoice and download invoice button label - By WebToffee ( WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels)
<?php //Do not copyt this line of code
add_filter('wt_pklist_alter_document_button_label','alter_btn_label',10,4);
function alter_btn_label($label,$action,$where,$template_type) {
if( "invoice" === $template_type) {
if("print" === $action) {
$label = __("Print Invoice","print-invoices-packing-slip-labels-for-woocommerce"); // Change label for print invoice button on my account order list, order details and order mail
}
if("download" === $action) {
$label = __("Download Invoice","print-invoices-packing-slip-labels-for-woocommerce"); // Change label for download invoice button on my account order list and order details pages
@webtoffee-git
webtoffee-git / function.php
Last active February 6, 2024 04:16
Code to auto update order status to processing for on-hold orders - By WebToffee (Stripe Payment Gateway Plugin)
<?php //Do not copy this line of code
add_action('woocommerce_order_status_changed', 'wt_woocommerce_order_status_changed', 10, 3);
function wt_woocommerce_order_status_changed($order_id, $old_status, $new_status)
{
if(!$order_id){
return;
}
$order = wc_get_order($order_id);
if(!$order){
@webtoffee-git
webtoffee-git / function.php
Created February 6, 2024 03:57
Code to add custom placeholder to non-order emails - By WebToffee (Decorator Email Customizer )
<?php //Do not copy this line of code
add_filter('wt_woomail_no_order_body_text','wbtf_add_custom_placeholder_to_user_emails',10,2);
function wbtf_add_custom_placeholder_to_user_emails($body_text, $email) {
if ( is_a( $email->object, 'WP_User' ) ) {
$body_text = str_replace( '{custom_value}', 'Actual data to replace', $body_text ); // Replace placeholder and value here
}