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;