Skip to content

Instantly share code, notes, and snippets.

View woocommerce_orderby_by_instock_first.php
<?php
/**
* Order product collections by stock status, instock products first.
*/
class iWC_Orderby_Stock_Status
{
public function __construct()
{
View woocommerce_additional_shipping_fee.php
<?php
//additional_shipping_fee
//add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_add_cart_fee' );
function bbloomer_add_cart_fee() {
$surcharge = 2; // 5% surcharge based on shipping cost
WC()->cart->add_fee( __('Handling', 'woocommerce'), $surcharge );
@cccamuseme
cccamuseme / custom_excerpt-read-more.php
Last active Mar 1, 2021
Custom WordPress blog excerpt and read more link
View custom_excerpt-read-more.php
<?php
// custom excerpt length
function my_custom_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'my_custom_excerpt_length', 999 );
// add more link to excerpt
function my_custom_excerpt_more($more) {
@cccamuseme
cccamuseme / custom_shortcode.php
Last active Oct 8, 2019
Create a custom WordPress shortcode that gets a file
View custom_shortcode.php
function my_custom_shortcode() {
ob_start();
get_template_part('custom_shortcode'); // get file custom_shortcode.php in your theme
return ob_get_clean();
}
add_shortcode( 'my_custom_shortcode', 'my_custom_shortcode' );
// shortcode to use [my_custom_shortcode]
@cccamuseme
cccamuseme / wc_redirect.php
Created Aug 22, 2019
woocommerce checkout redirect
View wc_redirect.php
add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'https://escatech.us/new-order-thankyou/' );
exit;
}
}
@cccamuseme
cccamuseme / enable_payment_method_from_user_profile_acf.php
Last active Jun 20, 2019
Enable or disable woocommerce payment gateway by ACF radio buttons in user profile.
View enable_payment_method_from_user_profile_acf.php
<?php
/*
* Enable COD for account holder
*/
function enable_cod_payment( $available_gateways ) {
global $woocommerce;
$user = wp_get_current_user();
$user_status = get_field('account_holder', $user );
@cccamuseme
cccamuseme / shipping_options.js
Last active Oct 1, 2018
Woocommerce shipping dropdown options. additional fields .show .hide based on selection.
View shipping_options.js
jQuery(function ($) {
$("#additional_Shipping_Method").change(function() {
var val = $(this).val();
if (val === "third-party") {
$("#additional_Carrier_Name_field").show();
$("#additional_Carrier_Account_Number_field").show();
}
else if (val === "collect") {
$("#additional_Carrier_Name_field").show();
@cccamuseme
cccamuseme / woocommerce_cart_links_login_logout.php
Last active Jul 11, 2018
Woocommerce links for login, logout, email as account link, and cart links showing quantity and total.
View woocommerce_cart_links_login_logout.php
@cccamuseme
cccamuseme / cpt-wp-query.php
Created May 21, 2018
Custom Post Type Query
View cpt-wp-query.php
<?php
$slider = new WP_Query(array( 'post_type' => 'project' ) );
if( $slider->have_posts() ) :
while($slider->have_posts()) :
$slider->the_post();
?>
<style type="text/css">
.project-box {
background-image: url('<?php the_field('featured_image') ?>');
@cccamuseme
cccamuseme / acf-slick-carousel-content-slider.php
Last active Jul 11, 2018
WordPress Advanced Custom Fields content slider
View acf-slick-carousel-content-slider.php