Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php Change the WooCommerce loop product link based on a custom field

function action_woocommerce_product_options_advanced() {  
    woocommerce_wp_text_input( 
        array( 
            'id'          => '_custom_url', 
            'label'       => __( 'Custom Page link', 'actions-pro' ), 
            'placeholder' => 'http://',
            'desc_tip'    => 'true',
            'description' => __( 'Enter the custom product page url for this product to link to from the shop page.', 'actions-pro' ) 
        )
    );
}
add_action( 'woocommerce_product_options_advanced', 'action_woocommerce_product_options_advanced' );

// Save custom field
function action_woocommerce_admin_process_product_object( $product ) {
    // Isset
    if ( isset( $_POST['_custom_url'] ) ) {        
        // Update
        $product->update_meta_data( '_custom_url', sanitize_url( $_POST['_custom_url'] ) );
    }
}
add_action( 'woocommerce_admin_process_product_object', 'action_woocommerce_admin_process_product_object', 10, 1 );

// Custom url
function filter_woocommerce_loop_product_link( $the_permalink, $product ) {
    // Get meta value
    $url = $product->get_meta( '_custom_url' );

    // NOT empty
    if ( ! empty ( $url ) ) {
        $the_permalink = $url;
    }

    return $the_permalink;
Comment

PREVIOUS NEXT
Code Example
Php :: run seeder command in laravel 
Php :: comparison operators in php 
Php :: how can i check that a json file already has something inside 
Php :: chunk in laravel 
Php :: Dein Benutzer-Profil um weitere Social Media Accounts erweitern 
Php :: php display result from html 
Php :: php shell_exec must be connected to a terminal 
Php :: laravel check if postback 
Php :: what is the fee/commission charge for payoneer 
Php :: php options list view sidebar (240 x 500), list view results (600 x 180), listing page (450 x 200) 
Php :: avoid sql injection in password field 
Php :: drop down list display only seleted item only 
Php :: php include inside function global 
Php :: If you wanted all questions that had all three of those tags, your query would look like: 
Php :: Sorting Products by Custom Meta Fields 
Php :: expression is not allowed as parameter 
Php :: vault create/enable secret engine 
Php :: object initialization 
Php :: php array dot notation 
Php :: wordpress how to string multple function.php files together 
Php :: https://stackoverflow.com/questions/58589741/angular-8-hide-divs-and-show-div-on-button-click 
Php :: get current tax page 
Php :: SELECT * FROM `phptrip` WHERE `dest`=`BIHAR` LIMIT 0, 25 
Php :: dropdown in crud application YII 
Php :: Multiple trait declaration in PHP 
Php :: laravel collection load 
Php :: Remove values from select list based on condition 
Php :: Call to a member function delete() on null laravel 8 
Php :: herencia php 
Php :: install wget downloader php 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =