Skip to content

Instantly share code, notes, and snippets.

View bolderelements's full-sized avatar

Erica Dion bolderelements

View GitHub Profile
@bolderelements
bolderelements / betrs-remove-table-id.php
Created July 17, 2023 16:15
Remove the extra number added to the Table Rate option ID
/*
* Remove the extra number added to the Table Rate option ID
*
* Requires Table Rate Shipping for WooCommerce 4.2+
*/
add_filter( 'betrs_calculated_table_rate_options', 'betrs_remove_table_id', 10, 1 );
function betrs_remove_table_id( $rates ) {
// look through all options created
if( is_array( $rates ) && count( $rates ) > 0 ) {
@bolderelements
bolderelements / betrs-modify-allowed-html-tags.php
Created November 30, 2022 21:29
Add <embed> tag to the allowed list for the Table Rate Shipping description field
/*
* Adds the <embed> tag to allowed tags in the Description field.
*
* Requires Table Rate Shipping for WooCommerce 4.2+
*/
add_filter( 'betrs_desc_allowed_tags', 'add_new_allowed_tags_betrs', 10, 1 );
function add_new_allowed_tags_betrs( $allowedtags ) {
$allowedtags['embed'] = array(
'src' => true,
@bolderelements
bolderelements / betrs-add-class-qty-condition.php
Created June 23, 2021 20:19
Add a new condition to the Table Rate method that checks quantity of specific shipping class
/**
* Add ability to check for quantity 3 of a specific shipping class in Table Rate method
* Intended for Use with Per Order setups and Method Conditions
* https://codecanyon.net/item/table-rate-shipping-for-woocommerce/3796656?ref=bolderelements
*
* Code should be added to a child theme's functions.php file
*/
function betrs_add_class_qty_cond( $conditions ) {
// add new option to list
$conditions['qty_shipping_class'] = '3 of Shipping Class';
@bolderelements
bolderelements / betrs-add-settings-field.php
Last active December 11, 2020 21:29
Add a form field to one of the sections in Table Rate method
/**
* Add form field to 'Additional Options' section in the Table of Rates
*
* @return string
*/
function betrs_add_settings_field( $settings ) {
// array of shipping provider codes
$shipping_carriers = array(
'usps' => 'US Postal Service',
'fedex' => 'FedEx',
@bolderelements
bolderelements / betrs-save-custom-meta.php
Created October 10, 2020 21:55
Get selection and save as shipping meta data
/**
* Find the custom column selection when calculating shipping
*
* @return string
*/
function betrs_add_custom_data_shipping_array( $shipping_options, $option, $option_ID, $row_ID ) {
// find selected value from table
$selection = ( isset( $option['rows'][ $row_ID ]['provider'] ) ) ? sanitize_text_field( $option['rows'][ $row_ID ]['provider'] ) : '';
@bolderelements
bolderelements / betrs-display-custom-column.php
Last active October 10, 2020 21:55
Display the custom column data on the cart and checkout pages
/**
* Display provider if applicable.
*
* @return void
*/
function betrs_display_provider( $method, $index ) {
$meta_data = $method->get_meta_data();
if( isset( $meta_data['provider'] ) ) {
echo '<p class="betrs_option_provider">Shipping Provider: ' . stripslashes( sanitize_text_field( $meta_data['provider'] ) ) . '</div>';
@bolderelements
bolderelements / betrs-save-column-data.php
Last active October 10, 2020 20:27
Save form field from custom column in the Table of Rates
/**
* Save form field from custom column in the Table of Rates
*
* @return string
*/
function betrs_save_column_data( $save_data, $option_ID, $row_ID ) {
// sanitize arguments
$option_ID = intval( $option_ID );
$row_ID = intval( $row_ID );
@bolderelements
bolderelements / betrs-add-column-data.php
Last active October 10, 2020 21:41
Add form field to custom column in the Table of Rates
/**
* Add form field to custom column in the Table of Rates
*
* @return string
*/
function betrs_add_column_data( $content, $item ) {
// find previously saved value
$saved = ( isset( $item['provider'] ) ) ? sanitize_text_field( $item['provider'] ) : '';
// array of shipping providers
@bolderelements
bolderelements / betrs-add-column.php
Last active October 10, 2020 19:52
Add a column to the Table of Rates
/**
* Add a column to the Table of Rates
*
* @return array
*/
function betrs_add_column( $columns ) {
// temporarily unset the last column (sort)
unset( $columns['sort'] );
// setup new column
@bolderelements
bolderelements / wc-add-tax-subtext-fees.php
Created July 10, 2020 19:05
Add tax subtext to Fees line similar to Subtotal and Shipping lines
/**
* Add tax subtext to Fees line
* Code snippets should be added to the functions.php file of your child theme
*
* @return string
*/
add_filter( 'woocommerce_cart_totals_fee_html', 'add_tax_subtext_on_fees', 10, 2 );
function add_tax_subtext_on_fees( $cart_totals_fee_html, $fee ) {
if( $fee->taxable ) {