Search
 
SCRIPT & CODE EXAMPLE
 

PHP

woocommerce_recently_viewed

/**
 * Track product views. Always.
 */
function wc_track_product_view_always() {
    if ( ! is_singular( 'product' ) /* xnagyg: remove this condition to run: || ! is_active_widget( false, false, 'woocommerce_recently_viewed_products', true )*/ ) {
        return;
    }

    global $post;

    if ( empty( $_COOKIE['woocommerce_recently_viewed'] ) ) { // @codingStandardsIgnoreLine.
        $viewed_products = array();
    } else {
        $viewed_products = wp_parse_id_list( (array) explode( '|', wp_unslash( $_COOKIE['woocommerce_recently_viewed'] ) ) ); // @codingStandardsIgnoreLine.
    }

    // Unset if already in viewed products list.
    $keys = array_flip( $viewed_products );

    if ( isset( $keys[ $post->ID ] ) ) {
        unset( $viewed_products[ $keys[ $post->ID ] ] );
    }

    $viewed_products[] = $post->ID;

    if ( count( $viewed_products ) > 15 ) {
        array_shift( $viewed_products );
    }

    // Store for session only.
    wc_setcookie( 'woocommerce_recently_viewed', implode( '|', $viewed_products ) );
}

remove_action('template_redirect', 'wc_track_product_view', 20);
add_action( 'template_redirect', 'wc_track_product_view_always', 20 );
Comment

PREVIOUS NEXT
Code Example
Php :: decrypt md5 php 
Php :: php read big file line by line 
Php :: laravel casts pivot table 
Php :: simple bindings laravel 
Php :: how to re assign value of associative array after assign in php 
Php :: Dynamic Carousel in Laravel not working displays only one image 
Php :: Call Python From PHP And Get Return Code 
Php :: selecting data from two tables in database php 
Php :: guzzlehttp http_errors get 
Php :: how to enable auto refresh on save 
Php :: laravel how to check app env 
Php :: php print fetch 
Php :: laravel get last created id 
Php :: $wpdb foreach 
Php :: send email php form 
Php :: toggle switch php 
Php :: difference between array_merge and + 
Php :: tenary php 
Php :: laravel automatically encrypt model atribute 
Php :: php unset by value 
Php :: php laravel string substring 
Php :: phpmailer send email to multiple addresses 
Php :: laravel relationship retrieve data 
Php :: mage log equivalent magento 2 
Php :: if certain condition is met exit if block php 
Php :: send gmail 
Php :: get from link php 
Php :: laravel image max size validation 
Php :: laravel database backup 
Php :: Laravel - multiple select query 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =