Skip to content

Instantly share code, notes, and snippets.

@cccamuseme
cccamuseme / custom_excerpt-read-more.php
Last active March 1, 2021 16:58
Custom WordPress blog excerpt and read more link
<?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 October 8, 2019 17:52
Create a custom WordPress shortcode that gets a file
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 August 22, 2019 19:37
woocommerce checkout redirect
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 June 20, 2019 20:32
Enable or disable woocommerce payment gateway by ACF radio buttons in user profile.
<?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 October 1, 2018 18:18
Woocommerce shipping dropdown options. additional fields .show .hide based on selection.
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 July 11, 2018 21:39
Woocommerce links for login, logout, email as account link, and cart links showing quantity and total.
@cccamuseme
cccamuseme / cpt-slider.php
Last active March 8, 2023 17:31
Custom Post Type Slider
<?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 July 11, 2018 21:45
WordPress Advanced Custom Fields content slider
@cccamuseme
cccamuseme / wordpress-featured-img-bg-fallback-img.php
Last active March 8, 2018 21:34
WordPress featured image as background with fallback image
<?php echo do_shortcode("[shortcode]"); ?>